Trouble sending videos with thumbnails using Telegram bot API

Hey everyone, I’m hitting a snag with my Telegram bot. I’m trying to send a video with a thumbnail, but I keep getting this error:

Can't parse inputmedia: media not found

I’m using Python 3.11.6 and the python-telegram-bot library version 20.7. Here’s a simplified version of my code:

file = OpenFile('my_video.mp4')
thumb = OpenFile('thumbnail.jpg')
video = MediaVideo(file=file, thumb=thumb)
print('Video prepared')
result = bot.send_group_media(chat_id=12345, media=[video])
print('Sent successfully')

The ‘Video prepared’ message shows up in the console, but it never gets to ‘Sent successfully’. Any ideas what might be going wrong? I’ve double-checked the file paths and they seem correct. Thanks in advance for any help!

have u tried using different file formats for the thumbnail? sometimes telegram can be picky. also, double-check ur chat_id is correct and the bot has permission to send media in that chat. might be worth trying to send the video without a thumb first, just to narrow down the issue

I’ve dealt with this exact problem before, and it can be frustrating. One thing that worked for me was ensuring the thumbnail image was in the correct format and size. Telegram prefers JPEG for thumbnails, and they should be no larger than 200x200 pixels. Also, make sure your bot has the necessary permissions in the chat you’re sending to.

If that doesn’t solve it, try using the sendVideo method instead of send_group_media. It’s a bit more straightforward:

with open('my_video.mp4', 'rb') as video_file, open('thumbnail.jpg', 'rb') as thumb_file:
    bot.send_video(chat_id=12345, video=video_file, thumb=thumb_file)

This approach has been more reliable in my experience. If you’re still having issues, it might be worth checking your bot’s token and ensuring it’s still valid. Sometimes these things can expire without us realizing it.

I’ve encountered similar issues before. One thing to check is the file size of both your video and thumbnail. Telegram has limits on file sizes, especially for bots. Try reducing the size of your files if they’re large.

Another potential issue could be with how you’re opening the files. Instead of using OpenFile, try opening them in binary mode:

with open('my_video.mp4', 'rb') as file, open('thumbnail.jpg', 'rb') as thumb:
    video = MediaVideo(media=file, thumb=thumb)
    result = bot.send_group_media(chat_id=12345, media=[video])

This ensures the files are properly read as binary data. If the problem persists, you might want to check the Telegram Bot API documentation for any recent changes or specific requirements for sending videos with thumbnails.