diff --git a/telebot/async_telebot.py b/telebot/async_telebot.py index 8234b5f..beaca2d 100644 --- a/telebot/async_telebot.py +++ b/telebot/async_telebot.py @@ -317,6 +317,14 @@ class AsyncTeleBot: except asyncio.CancelledError: return + except asyncio_helper.RequestTimeout as e: + logger.error(str(e)) + if non_stop: + await asyncio.sleep(2) + continue + else: + return + except asyncio_helper.ApiTelegramException as e: logger.error(str(e)) diff --git a/telebot/asyncio_helper.py b/telebot/asyncio_helper.py index 0360b09..eab1aea 100644 --- a/telebot/asyncio_helper.py +++ b/telebot/asyncio_helper.py @@ -34,21 +34,32 @@ CONNECT_TIMEOUT = 15 READ_TIMEOUT = 30 LONG_POLLING_TIMEOUT = 10 # Should be positive, short polling should be used for testing purposes only (https://core.telegram.org/bots/api#getupdates) - +REQUEST_TIMEOUT = 10 +MAX_RETRIES = 3 logger = telebot.logger -RETRY_ON_ERROR = False -RETRY_TIMEOUT = 2 -MAX_RETRIES = 15 - async def _process_request(token, url, method='get', params=None, files=None, request_timeout=None): params = compose_data(params, files) + if request_timeout is None: + request_timeout = REQUEST_TIMEOUT + timeout = aiohttp.ClientTimeout(total=request_timeout) + got_result = False + current_try=0 async with await session_manager._get_new_session() as session: - async with session.request(method=method, url=API_URL.format(token, url), data=params, timeout=request_timeout) as response: - logger.debug("Request: method={0} url={1} params={2} files={3} request_timeout={4}".format(method, url, params, files, request_timeout).replace(token, token.split(':')[0] + ":{TOKEN}")) - json_result = await _check_result(url, response) - if json_result: - return json_result['result'] + while not got_result and current_try