kollo
kollo

Reputation: 1311

Error sending image from file with python-telegram-bot

I have a problem sending photo from file with python telegram bot. It is working great with a picture URL but not when trying to send a file from disk.

Steps to reproduce

bot.send_photo(chat_id=update.message.chat_id, photo=open('/mydir/log.jpg', 'rb'))

getting error:

*** BadRequest: Url host is empty

Configuration

According to the doc we can pass file from disk : https://github.com/python-telegram-bot/python-telegram-bot/wiki/Code-snippets#post-an-image-file-from-disk

Upvotes: 2

Views: 3346

Answers (1)

kollo
kollo

Reputation: 1311

Problem was with the path of the photo that was in unicode.

photo = open(('/mydir/log.jpg').encode('utf-8'), 'rb')
bot.send_photo(chat_id=update.message.chat_id, photo=photo)

In the _ method of telegram.inputfile if you don't send a fully unicode form, the join make UnicodeDecodeError.

Upvotes: 4

Related Questions