Pyrogram Python fails to catch Exception

423 Views Asked by At

I'm trying to download pictures from Telegram with the Pyrogram API. After some images I do get ratelimited but the code fails to catch the exception an wait the given seconds.

I keep getting these errors and it continues my for loop instead of actually waiting to download the next image. It seems to me that within download_media() there is an own try catch block that precatches the error, I am not even printing the exception?

Telegram says: [420 FLOOD_WAIT_X] - A wait of 1219 seconds is required (caused by "auth.ExportAuthorization")
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/pyrogram/client.py", line 880, in get_file
    dc_id=dc_id
  File "/usr/local/lib/python3.7/dist-packages/pyrogram/methods/advanced/invoke.py", line 83, in invoke
    else self.sleep_threshold)
  File "/usr/local/lib/python3.7/dist-packages/pyrogram/session/session.py", line 389, in invoke
    return await self.send(query, timeout=timeout)
  File "/usr/local/lib/python3.7/dist-packages/pyrogram/session/session.py", line 357, in send
    RPCError.raise_it(result, type(data))
  File "/usr/local/lib/python3.7/dist-packages/pyrogram/errors/rpc_error.py", line 97, in raise_it
    is_signed=is_signed)
pyrogram.errors.exceptions.flood_420.FloodWait: Telegram says: [420 FLOOD_WAIT_X] - A wait of 1219 seconds is required (caused by `"auth.ExportAuthorization")

The code is the following…

try:
    downloaded_file = await app.download_media(new_message.photo, file_name=new_file_path, progress=progress)
except FloodWait as e:
    print("Now waiting seconds", e.value)
    await asyncio.sleep(e.value)  # Wait "value" seconds before continuing

I already tried to fix it based on the how to handle flood waits given by Pyrogram (https://docs.pyrogram.org/faq/how-to-avoid-flood-waits), but the catch block is simply never called.

0

There are 0 best solutions below