Reputation: 1311
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.
bot.send_photo(chat_id=update.message.chat_id, photo=open('/mydir/log.jpg', 'rb'))
getting error:
*** BadRequest: Url host is empty
OS: Osx
Python: 2.7 python
-m telegram
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
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