Remove auto retry requests on RetryAfter error.

This commit is contained in:
Alex Root Junior 2017-12-10 04:00:46 +02:00
parent f529f588da
commit 629dd400eb
2 changed files with 2 additions and 16 deletions

View file

@ -124,7 +124,7 @@ def _compose_data(params=None, files=None):
return data return data
async def request(session, token, method, data=None, files=None, continue_retry=False, **kwargs) -> bool or dict: async def request(session, token, method, data=None, files=None, **kwargs) -> bool or dict:
""" """
Make request to API Make request to API
@ -144,8 +144,6 @@ async def request(session, token, method, data=None, files=None, continue_retry=
:type data: :obj:`dict` :type data: :obj:`dict`
:param files: files :param files: files
:type files: :obj:`dict` :type files: :obj:`dict`
:param continue_retry:
:type continue_retry: :obj:`dict`
:return: result :return: result
:rtype :obj:`bool` or :obj:`dict` :rtype :obj:`bool` or :obj:`dict`
""" """
@ -158,11 +156,6 @@ async def request(session, token, method, data=None, files=None, continue_retry=
return await _check_result(method, response) return await _check_result(method, response)
except aiohttp.ClientError as e: except aiohttp.ClientError as e:
raise exceptions.NetworkError(f"aiohttp client throws an error: {e.__class__.__name__}: {e}") raise exceptions.NetworkError(f"aiohttp client throws an error: {e.__class__.__name__}: {e}")
except exceptions.RetryAfter as e:
if continue_retry:
await asyncio.sleep(e.timeout)
return await request(session, token, method, data, files, **kwargs)
raise
class Methods(Helper): class Methods(Helper):

View file

@ -18,7 +18,6 @@ class BaseBot:
loop: Optional[Union[asyncio.BaseEventLoop, asyncio.AbstractEventLoop]] = None, loop: Optional[Union[asyncio.BaseEventLoop, asyncio.AbstractEventLoop]] = None,
connections_limit: Optional[base.Integer] = 10, connections_limit: Optional[base.Integer] = 10,
proxy: str = None, proxy_auth: Optional[aiohttp.BasicAuth] = None, proxy: str = None, proxy_auth: Optional[aiohttp.BasicAuth] = None,
continue_retry: Optional[bool] = False,
validate_token: Optional[bool] = True): validate_token: Optional[bool] = True):
""" """
Instructions how to get Bot token is found here: https://core.telegram.org/bots#3-how-do-i-create-a-bot Instructions how to get Bot token is found here: https://core.telegram.org/bots#3-how-do-i-create-a-bot
@ -33,8 +32,6 @@ class BaseBot:
:type proxy: :obj:`str` :type proxy: :obj:`str`
:param proxy_auth: Authentication information :param proxy_auth: Authentication information
:type proxy_auth: Optional :obj:`aiohttp.BasicAuth` :type proxy_auth: Optional :obj:`aiohttp.BasicAuth`
:param continue_retry: automatic retry sent request when flood control exceeded
:type continue_retry: :obj:`bool`
:param validate_token: Validate token. :param validate_token: Validate token.
:type validate_token: :obj:`bool` :type validate_token: :obj:`bool`
:raise: when token is invalid throw an :obj:`aiogram.utils.exceptions.ValidationError` :raise: when token is invalid throw an :obj:`aiogram.utils.exceptions.ValidationError`
@ -48,9 +45,6 @@ class BaseBot:
self.proxy = proxy self.proxy = proxy
self.proxy_auth = proxy_auth self.proxy_auth = proxy_auth
# Action on error
self.continue_retry = continue_retry
# Asyncio loop instance # Asyncio loop instance
if loop is None: if loop is None:
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
@ -123,8 +117,7 @@ class BaseBot:
:raise: :obj:`aiogram.exceptions.TelegramApiError` :raise: :obj:`aiogram.exceptions.TelegramApiError`
""" """
return await api.request(self.session, self.__token, method, data, files, return await api.request(self.session, self.__token, method, data, files,
proxy=self.proxy, proxy_auth=self.proxy_auth, proxy=self.proxy, proxy_auth=self.proxy_auth)
continue_retry=self.continue_retry)
async def download_file(self, file_path: base.String, async def download_file(self, file_path: base.String,
destination: Optional[base.InputFile] = None, destination: Optional[base.InputFile] = None,