【发布时间】:2020-11-16 09:18:59
【问题描述】:
大家早上好。我想使用 Python 和 Telegram Bot 的 API 发送文档。 Bot 已成功创建,我也可以发送消息,但不幸的是,我无法发送笔记本电脑上的文档。
我的代码如下:
import requests
def telegram_bot_send_document():
bot_token = '####'
bot_chatID = '####'
file = open('test.txt', 'rb')
send_document = 'https://api.telegram.org/bot' + bot_token + '/sendDocument?chat_id=' + bot_chatID + '&multipart/form-data=' + str(file.read())
r = requests.post(send_document)
print(r.url)
return r.json()
输出总是:
{'ok': False, 'error_code': 400, 'description': 'Bad Request: there is no document in the request'}
【问题讨论】:
标签: python-requests python-telegram-bot