N
N
NeaEnot2021-06-18 20:38:01
Python
NeaEnot, 2021-06-18 20:38:01

How to solve problems with sending large videos through Pyrogram?

Good afternoon. When trying to send a large video (> 10mb) to telegram through the Pyrogram library, there are problems. Up to a certain point, the download goes smoothly, and then stops and after a while gives the following messages:
[5] Retrying "upload.SaveBigFilePart" due to TimeoutError()
and
[5] Retrying "upload.SaveBigFilePart" due to OSError().

60ccd7fdeca7a526691036.jpeg

After that, the download continues, but after a full download, the exception "OSError: [WinError 10038] An attempt was made to perform an operation on an object that is not a socket"

from pyrogram import Client, filters
from hachoir.metadata import extractMetadata
from hachoir.parser import createParser
from datetime import datetime

def progress(current, total):
    print(f"{current * 100 / total:.1f}% : {datetime.now().strftime('%d_%H:%M:%S')}")

api_id = 0
api_hash = ''

video = r'D:\Downloads\test video.mp4'

metadata = extractMetadata(createParser(video))
duration = (0, metadata.get('duration').seconds)[metadata.has('duration')]
width = (0, metadata.get('width'))[metadata.has('width')]
height = (0, metadata.get('height'))[metadata.has('height')]

app = Client('test_session', api_id, api_hash)

with app:
    dialogs = app.get_dialogs(0)
    channel = None

    for dialog in dialogs:
        if dialog.chat.title == 'test':
            channel = dialog.chat

    app.send_video(channel.id, video, caption='Pyrogram test', progress=progress, duration=duration, width=width, height=height)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question