Handle FloodWaitError in client.download_media

Fixes #1426. Not entirely happy with the new indirection layer,
but the original __call__ method is already a mess anyway and
the additional cost of an extra call should be neglible compared
to the actual IO.
This commit is contained in:
Lonami Exo
2020-04-28 20:49:57 +02:00
parent 7f3aa43ad4
commit 7ea4686d6c
3 changed files with 6 additions and 3 deletions

View File

@@ -27,6 +27,9 @@ def _fmt_flood(delay, request, *, early=False, td=datetime.timedelta):
class UserMethods:
async def __call__(self: 'TelegramClient', request, ordered=False):
return await self._call(self._sender, request, ordered=ordered)
async def _call(self: 'TelegramClient', sender, request, ordered=False):
requests = (request if utils.is_list_like(request) else (request,))
for r in requests:
if not isinstance(r, TLRequest):
@@ -50,7 +53,7 @@ class UserMethods:
self._last_request = time.time()
for attempt in retry_range(self._request_retries):
try:
future = self._sender.send(request, ordered=ordered)
future = sender.send(request, ordered=ordered)
if isinstance(future, list):
results = []
exceptions = []