mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
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
This commit is contained in:
parent
5e5c0daa87
commit
f7e0d13fe6
@ -180,6 +180,7 @@ def load_data(url=None, filepath=None,
|
|||||||
data = io.BytesIO(req.content)
|
data = io.BytesIO(req.content)
|
||||||
if data.read():
|
if data.read():
|
||||||
data.seek(0)
|
data.seek(0)
|
||||||
|
data.name = url
|
||||||
return data
|
return data
|
||||||
_LOGGER.warning("Empty data (retry #%s) in %s).",
|
_LOGGER.warning("Empty data (retry #%s) in %s).",
|
||||||
retry_num + 1, url)
|
retry_num + 1, url)
|
||||||
@ -503,7 +504,7 @@ class TelegramNotificationService:
|
|||||||
_LOGGER.debug("send file to chat_id %s. Caption: %s.",
|
_LOGGER.debug("send file to chat_id %s. Caption: %s.",
|
||||||
chat_id, caption)
|
chat_id, caption)
|
||||||
self._send_msg(func_send, "Error sending file",
|
self._send_msg(func_send, "Error sending file",
|
||||||
chat_id, io.BytesIO(file_content.read()),
|
chat_id, file_content,
|
||||||
caption=caption, **params)
|
caption=caption, **params)
|
||||||
file_content.seek(0)
|
file_content.seek(0)
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user