Can't use edit_message_media, "Media is not specified"
- What version of pyTelegramBotAPI are you using? pyTelegramBotAPI 3.6.6
- What OS are you using? Linux Ubuntu 18.04
- What version of python are you using? Python 3.6.7
Hi, I'm trying to edit a photo in a message with edit_message_media endpoint but Telegram still response with 400:Media is not specified. So, I'm using PySnooper to debug, and from the output the function doesn't set my media (passed as argument) in 'media' into payload. I've tried passing media as a link, as a path to an image file and as a byte object (with open()) but it keep fail.
Here is the code and the output
bot.edit_message_media(media,message.chat.id,message.message_id)
9:22:28.832923 line 48 bot.edit_message_media(media=media,chat_id=message.chat.id,message_id=message.message_id)
2019-05-08 19:22:28,833 (apihelper.py:45 WorkerThread1) DEBUG - TeleBot: "Request: method=get url=https://api.telegram.org/bot<token>/editMessageMedia params={'media': None, 'chat_id': 1234..., 'message_id': 13388} files=None"
2019-05-08 19:22:28,881 (apihelper.py:55 WorkerThread1) DEBUG - TeleBot: "The server returned: 'b'{"ok":false,"error_code":400,"description":"Bad Request: can\'t parse InputMedia: Media is not specified"}''"
The interesting part is "... params={'media': None ..."
Best regards, Luca.
Here is the code and the output bot.edit_message_media(media,message.chat.id,message.message_id)
And what is "media"? pyTelegramBot says it is None, that's why you have an error from Telegram...
I've passed media as a link to a remote image (both http and https), as a path to a local image (/home/.../image.jpg) and as a byte object with open() function, but the problem is still that the edit_message_media function doesn't set the "media" argument into payload for Telegram.
@xLinkOut it's lib bug/lack of annotations. you need to wrap file_id/url
bot.edit_message_media(InputMediaPhoto(file_id), id, message_id=msg_id)
@alexshavelev44, the method you suggested looks correct to me, but when I used it the way you described, it throws an error 400, even though the url link is reachable via browser. Any other suggestion you could make?
@alexshavelev44, the method you suggested looks correct to me, but when I used it the way you described, it throws an error 400, even though the url link is reachable via browser. Any other suggestion you could make?
show code + error
Have the same problem, and this helps me:
from telebot import types
image = open('image.jpg', 'rb')
bot.edit_message_media(media=types.InputMedia(type='photo', media=image),
chat_id=call.message.chat.id,
message_id=call.message.message_id,
reply_markup=markup)
I have same problem... what is the media exactly? can I put file_id instead of media?
media should be of type types.InputMedia.
types.InputMediaPhoto(media)
worked fine for me here my media was a url.