From f7e0d13fe60076ae7eec9023c7c2cf6af0252924 Mon Sep 17 00:00:00 2001 From: Eugenio Panadero Date: Mon, 29 May 2017 22:59:44 +0200 Subject: [PATCH] Telegram send image: fix mimetype detection (#7802) * 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 --- homeassistant/components/telegram_bot/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/telegram_bot/__init__.py b/homeassistant/components/telegram_bot/__init__.py index 9bcc5a82b58..127caba34a0 100644 --- a/homeassistant/components/telegram_bot/__init__.py +++ b/homeassistant/components/telegram_bot/__init__.py @@ -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) @@ -503,7 +504,7 @@ class TelegramNotificationService: _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: