我正在尝试使用python中的requests
将html文档发送给机器人。
url = 'https://api.telegram.org/bot******/sendDocument'
response = requests.post( url = url,
data = { 'chat_id' : chat_id,
'document': open('/home/user/page.html', 'rb'),
}
)
我得到<Response [400]>
。我遵循了这个link,并且能够使用curl
而不是使用requests
将html文档发布到漫游器。
我在这里做什么错了。
答案 0 :(得分:1)
这是您使用电报bot API发送本地文档的方式
import requests
BOT_TOKEN = " ... "
CHAT_ID = " ... "
url = f"https://api.telegram.org/bot{BOT_TOKEN}/sendDocument"
response = requests.post(url=url,
data={
'chat_id': CHAT_ID,
'document': 'attach://file',
},
files={
'file': open('./page.html', 'rb'),
}
)
print(response.json())