python: set reasonable timeouts for account requests

`requests` library does not have a timeout at all by default.
This commit is contained in:
link2xt
2023-01-05 22:59:12 +00:00
parent eba96eb904
commit f4c674fa98
2 changed files with 5 additions and 2 deletions

View File

@@ -12,8 +12,11 @@ from .rpc import Rpc
async def get_temp_credentials() -> dict:
url = os.getenv("DCC_NEW_TMP_EMAIL")
assert url, "Failed to get online account, DCC_NEW_TMP_EMAIL is not set"
# Replace default 5 minute timeout with a 1 minute timeout.
timeout = aiohttp.ClientTimeout(total=60)
async with aiohttp.ClientSession() as session:
async with session.post(url) as response:
async with session.post(url, timeout=timeout) as response:
return json.loads(await response.text())