From 6294c3265630542221e870f9691e429500b02425 Mon Sep 17 00:00:00 2001 From: Ruoqi Yang Date: Sun, 18 Sep 2022 14:08:14 +0800 Subject: - config httpx timeout - trace.moe api call upload image --- ATRI/utils/request.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'ATRI/utils') diff --git a/ATRI/utils/request.py b/ATRI/utils/request.py index 04d7093..d8f7be5 100644 --- a/ATRI/utils/request.py +++ b/ATRI/utils/request.py @@ -3,6 +3,9 @@ import httpx from ATRI.config import BotSelfConfig from ATRI.log import logger as log +timeout = BotSelfConfig.request_timeout +if timeout: + timeout = httpx.Timeout(timeout) if not BotSelfConfig.proxy: proxy = dict() @@ -12,11 +15,11 @@ else: async def get(url: str, **kwargs): log.debug(f"GET {url} by {proxy if proxy else 'No proxy'} | MORE: \n {kwargs}") - async with httpx.AsyncClient(proxies=proxy) as client: # type: ignore + async with httpx.AsyncClient(proxies=proxy, timeout=timeout) as client: # type: ignore return await client.get(url, **kwargs) async def post(url: str, **kwargs): log.debug(f"POST {url} by {proxy if proxy else 'No proxy'} | MORE: \n {kwargs}") - async with httpx.AsyncClient(proxies=proxy) as client: # type: ignore + async with httpx.AsyncClient(proxies=proxy, timeout=timeout) as client: # type: ignore return await client.post(url, **kwargs) -- cgit v1.2.3