如何使用python bot将本地html文件发送到Telegram

时间:2020-06-23 13:57:24

标签: python python-3.6 telegram-bot

这是我的代码

file_address = './charts/candle_chart.html'
response = bot.sendDocument(chat_id=chat_id, document=file_address, timeout=timeout)

但是我收到了host not found错误的异常

电报认为此文件在网络上

有人可以帮我吗!

1 个答案:

答案 0 :(得分:2)

电报机器人的文档说:

The document argument can be either a file_id, an URL or a file from disk: open(filename, 'rb')

所以它一定是这样的:

html_file = open('./charts/candle_chart.html', 'rb')
response = bot.sendDocument(chat_id=chat_id, document=html_file, timeout=timeout)

有关更多信息,请参见documentation