diff --git a/db_calls.py b/db_calls.py index 7cb3c33..0cc3087 100644 --- a/db_calls.py +++ b/db_calls.py @@ -67,7 +67,9 @@ async def db_get( log_string = f"get:\n{endpoint} id: {object_id} params: {params}" logger.info(log_string) if master_debug else logger.debug(log_string) - async with aiohttp.ClientSession(headers=AUTH_TOKEN) as session: + async with aiohttp.ClientSession( + headers=AUTH_TOKEN, timeout=aiohttp.ClientTimeout(total=timeout) + ) as session: async with session.get(req_url) as r: logger.info(f"session info: {r}") if r.status == 200: @@ -88,7 +90,9 @@ async def url_get(url: str, timeout: int = 3): log_string = f"get:\n{url}" logger.info(log_string) if master_debug else logger.debug(log_string) - async with aiohttp.ClientSession() as session: + async with aiohttp.ClientSession( + timeout=aiohttp.ClientTimeout(total=timeout) + ) as session: async with session.get(url) as r: if r.status == 200: log_string = "200 received" @@ -107,7 +111,9 @@ async def db_patch( log_string = f"patch:\n{endpoint} {params}" logger.info(log_string) if master_debug else logger.debug(log_string) - async with aiohttp.ClientSession(headers=AUTH_TOKEN) as session: + async with aiohttp.ClientSession( + headers=AUTH_TOKEN, timeout=aiohttp.ClientTimeout(total=timeout) + ) as session: async with session.patch(req_url) as r: if r.status == 200: js = await r.json() @@ -126,7 +132,9 @@ async def db_post( log_string = f"post:\n{endpoint} payload: {payload}\ntype: {type(payload)}" logger.info(log_string) if master_debug else logger.debug(log_string) - async with aiohttp.ClientSession(headers=AUTH_TOKEN) as session: + async with aiohttp.ClientSession( + headers=AUTH_TOKEN, timeout=aiohttp.ClientTimeout(total=timeout) + ) as session: async with session.post(req_url, json=payload) as r: if r.status == 200: js = await r.json() @@ -145,7 +153,9 @@ async def db_put( log_string = f"put:\n{endpoint} payload: {payload}\ntype: {type(payload)}" logger.info(log_string) if master_debug else logger.debug(log_string) - async with aiohttp.ClientSession(headers=AUTH_TOKEN) as session: + async with aiohttp.ClientSession( + headers=AUTH_TOKEN, timeout=aiohttp.ClientTimeout(total=timeout) + ) as session: async with session.put(req_url, json=payload) as r: if r.status == 200: js = await r.json() @@ -162,7 +172,9 @@ async def db_delete(endpoint: str, object_id: int, api_ver: int = 2, timeout=3): log_string = f"delete:\n{endpoint} {object_id}" logger.info(log_string) if master_debug else logger.debug(log_string) - async with aiohttp.ClientSession(headers=AUTH_TOKEN) as session: + async with aiohttp.ClientSession( + headers=AUTH_TOKEN, timeout=aiohttp.ClientTimeout(total=timeout) + ) as session: async with session.delete(req_url) as r: if r.status == 200: js = await r.json()