diff --git a/telebot/asyncio_helper.py b/telebot/asyncio_helper.py index 2836e3ec2..485dd19db 100644 --- a/telebot/asyncio_helper.py +++ b/telebot/asyncio_helper.py @@ -1,4 +1,4 @@ -import asyncio # for future uses +import asyncio import ssl import threading import aiohttp @@ -26,6 +26,11 @@ REQUEST_TIMEOUT = 300 MAX_RETRIES = 3 +# Retrying on network errors is opt-in, mirroring telebot.apihelper: +# when RETRY_ON_ERROR is True, requests failing with a network error are +# repeated up to MAX_RETRIES times with RETRY_TIMEOUT seconds in between. +RETRY_ON_ERROR = False +RETRY_TIMEOUT = 2 REQUEST_LIMIT = 50 @@ -90,29 +95,30 @@ async def _process_request(token, url, method='get', params=None, files=None, ** params = _prepare_data(params, files) timeout = aiohttp.ClientTimeout(total=request_timeout) - got_result = False - current_try=0 + current_try = 0 + max_tries = MAX_RETRIES if RETRY_ON_ERROR else 1 session = await session_manager.get_session() - while not got_result and current_try