Skip to content

Commit

Permalink
Telegram send image: fix mimetype detection (#7802)
Browse files Browse the repository at this point in the history
* Add `name` var to BytesIO content to get recognized

Sometimes the python-telegram-bot doesn't recognize the mimetype of the file and looks after a name variable to deduce it. Fixes #7413

* bytesio stream recycle less explicit
  • Loading branch information
azogue authored and pvizeli committed May 29, 2017
1 parent 5e5c0da commit f7e0d13
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion homeassistant/components/telegram_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ def load_data(url=None, filepath=None,
data = io.BytesIO(req.content)
if data.read():
data.seek(0)
data.name = url
return data
_LOGGER.warning("Empty data (retry #%s) in %s).",
retry_num + 1, url)
Expand Down Expand Up @@ -503,7 +504,7 @@ def send_file(self, is_photo=True, target=None, **kwargs):
_LOGGER.debug("send file to chat_id %s. Caption: %s.",
chat_id, caption)
self._send_msg(func_send, "Error sending file",
chat_id, io.BytesIO(file_content.read()),
chat_id, file_content,
caption=caption, **params)
file_content.seek(0)
else:
Expand Down

0 comments on commit f7e0d13

Please sign in to comment.