OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Pyrogram Python fails to catch Exception

  • Thread starter Thread starter yuskox
  • Start date Start date
Y

yuskox

Guest
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?

Code:
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…

Code:
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.
<p>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.</p>
<p>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?</p>
<pre><code>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")
</code></pre>
<p>The code is the following…</p>
<pre><code>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
</code></pre>
<p>I already tried to fix it based on the how to handle flood waits given by Pyrogram (<a href="https://docs.pyrogram.org/faq/how-to-avoid-flood-waits" rel="nofollow noreferrer">https://docs.pyrogram.org/faq/how-to-avoid-flood-waits</a>), but the catch block is simply never called.</p>
 

Latest posts

A
Replies
0
Views
1
Aarif Hussain A Nassar
A
F
Replies
0
Views
1
Fahmi Nur Fachrurozi
F
Top