pyTelegramBotAPI icon indicating copy to clipboard operation
pyTelegramBotAPI copied to clipboard

Can't use edit_message_media, "Media is not specified"

Open xLinkOut opened this issue 7 years ago • 9 comments

  1. What version of pyTelegramBotAPI are you using? pyTelegramBotAPI 3.6.6
  2. What OS are you using? Linux Ubuntu 18.04
  3. 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.

xLinkOut avatar May 08 '19 17:05 xLinkOut

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...

Badiboy avatar Jun 10 '19 12:06 Badiboy

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 avatar Jun 11 '19 14:06 xLinkOut

@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)

olekshchavelev avatar Jun 26 '19 13:06 olekshchavelev

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

arturbek avatar Jan 12 '20 20:01 arturbek

@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

olekshchavelev avatar Mar 21 '20 20:03 olekshchavelev

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)

Pushokkk avatar Mar 21 '20 20:03 Pushokkk

I have same problem... what is the media exactly? can I put file_id instead of media?

hamidko avatar Apr 18 '20 22:04 hamidko

media should be of type types.InputMedia.

Badiboy avatar Jul 20 '20 22:07 Badiboy

types.InputMediaPhoto(media)

worked fine for me here my media was a url.

blkksheepp avatar Dec 18 '20 19:12 blkksheepp