Answer the question
In order to leave comments, you need to log in
How to send many photos using Telegram Bot Api, Python?
I am writing a bot using PyTelegramBotApi , there was a need to send a lot of photos, preferably in one message (along with text), well, or in several messages. Every time there is an error, does not allow to send. Maybe there is some method in the API that allows you to perform many of the same operations, or is there a way to send a lot of photos?
Thank you very much
Here is the code:
for j in vkarr[2]:
time.sleep(.25)
urllib.request.urlretrieve(j,'temp.jpg')
img=open('temp.jpg','rb')
bot .send_chat_action(message.from_user.id, 'upload_photo')
bot.send_photo
(message.from_user.id,img)
img.close()
2017-04-11 12:15:23,893 (apihelper.py:42 WorkerThread2) DEBUG - TeleBot: "The server returned: 'b'{"ok":false,"error_code":400,"description":"Bad Request : IMAGE_PROCESS_FAILED"}''"
2017-04-11 12:15:23,893 (util.py:60 WorkerThread2) DEBUG - TeleBot: "Exception occurred"
2017-04-11 12:15:23,894 (__init__.py:250 MainThread ) ERROR - TeleBot: "A request to the Telegram API was unsuccessful. The server returned HTTP 400 Bad Request. Response body:
[b'{"ok":false,"error_code":400,"description":"Bad Request: IMAGE_PROCESS_FAILED"}']"
2017-04-11 12:15:23,894 (__init__.py:257 MainThread) INFO - TeleBot: "Waiting for 0.25 seconds until retry"
Answer the question
In order to leave comments, you need to log in
I solved the issue like this:
bot.send_media_group(chatid,
[InputMediaPhoto(msg.message.photo.file_id),
InputMediaVideo(msg.message.video.file_id)])
Telegram Bot API does not provide such mechanisms. If you want to send multiple photos - make a loop.
def send_many(photos, id):
for p in photos:
bot.send_photo(id, p)
bot.send_message(id, '<a href="IMG_URL">​</a>',
parse_mode="HTML")
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question