Checklist
- [X] I am sure the error is coming from Pyrogram's code and not elsewhere.
- [X] I have searched in the issue tracker for similar bug reports, including closed ones.
- [X] I ran
pip3 install -U https://github.com/pyrogram/pyrogram/archive/master.zip
and reproduced the issue using the latest development version.
Description
Im using pyrogram to forward messages to another system, using a raw handler to process the messages and also download corresponding media (mostly images).
Im using the client.download_media method. This works for almost all messages but for some it just wont download the images and return None as a path. I could not figure out why it happens but identified some messages for which it consistently happens.
I made a small testcase that fetches one of these messages from a channel and tries to download the media.
The message looks like this:
{
"_": "Message",
"message_id": 5869,
"sender_chat": {
"_": "Chat",
"id": -1001133587448,
"type": "channel",
"is_verified": false,
"is_restricted": false,
"is_creator": false,
"is_scam": false,
"is_fake": false,
"title": "Klondike (Crypto Rush) ⚠️",
"username": "CryptoKlondike",
"photo": {
"_": "ChatPhoto",
"small_file_id": "AQADBAATtJV9J10AAwIAAwjEyecW____ZkFiWLn_WDe_GwQAAR4E",
"small_photo_unique_id": "AQADtJV9J10AA78bBAAB",
"big_file_id": "AQADBAATtJV9J10AAwMAAwjEyecW____ZkFiWLn_WDfBGwQAAR4E",
"big_photo_unique_id": "AQADtJV9J10AA8EbBAAB"
},
"dc_id": 4
},
"date": "2021-02-19 10:35:42",
"chat": {
"_": "Chat",
"id": -1001133587448,
"type": "channel",
"is_verified": false,
"is_restricted": false,
"is_creator": false,
"is_scam": false,
"is_fake": false,
"title": "Klondike (Crypto Rush) ⚠️",
"username": "CryptoKlondike",
"photo": {
"_": "ChatPhoto",
"small_file_id": "AQADBAATtJV9J10AAwIAAwjEyecW____ZkFiWLn_WDe_GwQAAR4E",
"small_photo_unique_id": "AQADtJV9J10AA78bBAAB",
"big_file_id": "AQADBAATtJV9J10AAwMAAwjEyecW____ZkFiWLn_WDfBGwQAAR4E",
"big_photo_unique_id": "AQADtJV9J10AA8EbBAAB"
},
"dc_id": 4
},
"mentioned": false,
"scheduled": false,
"from_scheduled": false,
"media": true,
"author_signature": "Robert Mercer 🔥",
"caption_entities": [
{
"_": "MessageEntity",
"type": "bold",
"offset": 0,
"length": 15
},
{
"_": "MessageEntity",
"type": "bold",
"offset": 36,
"length": 7
},
{
"_": "MessageEntity",
"type": "bold",
"offset": 44,
"length": 4
},
{
"_": "MessageEntity",
"type": "bold",
"offset": 114,
"length": 6
}
],
"photo": {
"_": "Photo",
"file_id": "AgACAgQAAx0CQ5Er-AACFu1gcwc0j8RpzQcWvVFQOom1Zz4iLwACtbgxG8ydgVEdyclzkLTMRe9xGypdAAMBAAMCAAN5AAPDxAIAAR4E",
"file_unique_id": "AQAD73EbKl0AA8PEAgAB",
"width": 1280,
"height": 782,
"file_size": 83252,
"date": "2021-02-19 10:35:42",
"thumbs": [
{
"_": "Thumbnail",
"file_id": "AgACAgQAAx0CQ5Er-AACFu1gcwc0j8RpzQcWvVFQOom1Zz4iLwACtbgxG8ydgVEdyclzkLTMRe9xGypdAAMBAAMCAANtAAPExAIAAR4E",
"file_unique_id": "AQAD73EbKl0AA8TEAgAB",
"width": 320,
"height": 196,
"file_size": 14143
},
{
"_": "Thumbnail",
"file_id": "AgACAgQAAx0CQ5Er-AACFu1gcwc0j8RpzQcWvVFQOom1Zz4iLwACtbgxG8ydgVEdyclzkLTMRe9xGypdAAMBAAMCAAN4AAPFxAIAAR4E",
"file_unique_id": "AQAD73EbKl0AA8XEAgAB",
"width": 800,
"height": 489,
"file_size": 52220
}
]
},
"caption": "🐝 BTC UPDATE\n\nWe just stick to our initial plan and holding a big bag of Bitcoin. The target is still the same - $60000.",
"views": 14444,
"outgoing": false
}
Steps to Reproduce
This is my test code to fetch the message and download the media photo:
from pyrogram import Client, filters, idle
from pyrogram.handlers import MessageHandler
import time
import logging
client = Client(
'',
api_id='',
api_hash=''
)
def handle_new_impl(client:Client, message):
print(f"New message: {str(message)}")
def handle_new(client, message):
return handle_new_impl(client, message)
def main():
# Pyrogram setup
client.add_handler(MessageHandler(handle_new))
client.start()
m = client.get_messages(-1001133587448, 5869, replies=0)
path = None
print(f'Found message: {str(m)}')
path = client.download_media(m, file_name="test1.jpg", block=False)
print(f'Downloaded to: {str(path)}')
idle()
client.stop()
if __name__ == '__main__':
main()
Ive tried with block=False and block=True
When using block=True I get a getFile timeout error from the network code. When I use block=False I just get None as a path.
Ive also tried using the file reference, adding a filename, basically trying all the different parameters of downloade_media with no luck. Its not a huge image either. It works when I try to download the same image if posted in another channel for example.
Traceback
This is the traceback for using block=True
[520 Unknown error]: [-503 Timeout] (caused by "upload.GetFile")
Traceback (most recent call last):
File "/home/workspace/telegram/github_pyrogram/pyrogram/client.py", line 939, in get_file
r = await session.send(
File "/home/workspace/telegram/github_pyrogram/pyrogram/session/session.py", line 425, in send
return await self._send(data, timeout=timeout)
File "/home/workspace/telegram/github_pyrogram/pyrogram/session/session.py", line 395, in _send
RPCError.raise_it(result, type(data))
File "/home/workspace/telegram/github_pyrogram/pyrogram/errors/rpc_error.py", line 59, in raise_it
raise UnknownError(
pyrogram.errors.rpc_error.UnknownError: [520 Unknown error]: [-503 Timeout] (caused by "upload.GetFile")
Downloaded to: None
Just for the sake of reproducing above code, the channel I used it on is this https://t.me/CryptoKlondike (remove it if links are not allowed plz) Its a very big channel, maybe it has something to do with it. But it does happen with other channels aswell.
Any pointers on how to fix this would be much appreciated!