Error sending image from file with python-telegram-bot

Viewed 2799

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

  • OS: Osx

  • Python: 2.7 python

  • -m telegram

    • _python-telegram-bot 8.0
    • certifi 2017.07.27.1
    • future 0.16.0
    • Python 2.7.13 (default, Dec 18 2016, 07:03:39) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)]_

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

1 Answers

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.

Related