diff --git a/telethon/client/telegrambaseclient.py b/telethon/client/telegrambaseclient.py index 1b26eb5d..a7aec132 100644 --- a/telethon/client/telegrambaseclient.py +++ b/telethon/client/telegrambaseclient.py @@ -77,8 +77,7 @@ class TelegramBaseClient(abc.ABC): when Telegram is having internal issues (due to either ``errors.ServerError`` or ``errors.RpcCallFailError``), when there is a ``errors.FloodWaitError`` less than - ``session.flood_sleep_threshold``, or when there's a - migrate error. + `flood_sleep_threshold`, or when there's a migrate error. May set to a false-y value (``0`` or ``None``) for infinite retries, but this is not recommended, since some requests can @@ -95,9 +94,13 @@ class TelegramBaseClient(abc.ABC): Whether reconnection should be retried `connection_retries` times automatically if Telegram disconnects us or not. - report_errors (`bool`, optional): - Whether to report RPC errors or not. Defaults to ``True``, - see :ref:`api-status` for more information. + flood_sleep_threshold (`int` | `float`, optional): + The threshold below which the library should automatically + sleep on flood wait errors (inclusive). For instance, if a + ``FloodWaitError`` for 17s occurs and `flood_sleep_threshold` + is 20s, the library will ``sleep`` automatically. If the error + was for 21s, it would ``raise FloodWaitError`` instead. Values + larger than a day (like ``float('inf')``) will be changed to a day. device_model (`str`, optional): "Device model" to be sent when creating the initial connection. @@ -138,7 +141,7 @@ class TelegramBaseClient(abc.ABC): request_retries=5, connection_retries=5, auto_reconnect=True, - report_errors=True, + flood_sleep_threshold=60, device_model=None, system_version=None, app_version=None, @@ -170,7 +173,7 @@ class TelegramBaseClient(abc.ABC): DEFAULT_PORT ) - session.report_errors = report_errors + self.flood_sleep_threshold = flood_sleep_threshold self.session = session self.api_id = int(api_id) self.api_hash = api_hash diff --git a/telethon/client/users.py b/telethon/client/users.py index 10785e38..393069ed 100644 --- a/telethon/client/users.py +++ b/telethon/client/users.py @@ -37,7 +37,7 @@ class UserMethods(TelegramBaseClient): __log__.warning('Telegram is having internal issues %s: %s', e.__class__.__name__, e) except (errors.FloodWaitError, errors.FloodTestPhoneWaitError) as e: - if e.seconds <= self.session.flood_sleep_threshold: + if e.seconds <= self.flood_sleep_threshold: __log__.info('Sleeping for %ds on flood wait', e.seconds) await asyncio.sleep(e.seconds, loop=self._loop) else: diff --git a/telethon/sessions/abstract.py b/telethon/sessions/abstract.py index 72a0782f..b6f86a4d 100644 --- a/telethon/sessions/abstract.py +++ b/telethon/sessions/abstract.py @@ -3,18 +3,13 @@ from abc import ABC, abstractmethod class Session(ABC): def __init__(self): - # Session IDs can be random on every connection - self._report_errors = True - self._flood_sleep_threshold = 60 + pass def clone(self, to_instance=None): """ Creates a clone of this session file. """ - cloned = to_instance or self.__class__() - cloned._report_errors = self.report_errors - cloned._flood_sleep_threshold = self.flood_sleep_threshold - return cloned + return to_instance or self.__class__() @abstractmethod def set_dc(self, dc_id, server_address, port): @@ -145,34 +140,3 @@ class Session(ABC): ``id`` and ``access_hash`` in that order. """ raise NotImplementedError - - @property - def report_errors(self): - """ - Whether RPC errors should be reported - to https://rpc.pwrtelegram.xyz or not. - """ - return self._report_errors - - @report_errors.setter - def report_errors(self, value): - """ - Sets the boolean value that indicates whether RPC errors - should be reported to https://rpc.pwrtelegram.xyz or not. - """ - self._report_errors = value - - @property - def flood_sleep_threshold(self): - """ - Threshold below which the library should automatically sleep - whenever a FloodWaitError occurs to prevent it from raising. - """ - return self._flood_sleep_threshold - - @flood_sleep_threshold.setter - def flood_sleep_threshold(self, value): - """ - Sets the new time threshold (integer, float or timedelta). - """ - self._flood_sleep_threshold = value