在电报机器人上发送本地托管的照片

时间:2018-12-13 16:06:35

标签: python telegram telegram-bot python-telegram-bot

我正在使用api.telegram.bot和requests发送消息和图像。

requests.get(url + 'sendMessage', params=dict(chat_id=send_to_user_id,text="Messo"))

这很好。我的电报用户可以接收到消息“ Messo”。

现在,我正在尝试使用sendPhoto发送我在本地驱动器上托管的图像。

path = "kings/test_screenie1.png"
requests.get(url + 'sendPhoto', params=dict(chat_id=send_to_user_id, photo=open(path,'rb')))

我没有任何异常,但是,我的用户没有收到图像。我在Jupyter笔记本中获得的输出是:<Response [414]>

运行此代码的我的.ipynb文件位于:/Users/abc/Desktop/webproject/play0.ipynb

我的图像文件位于:/Users/abc/Desktop/webproject/kings/test_screenie1.png

我正在Mac OS上运行它。

1 个答案:

答案 0 :(得分:0)

请尝试以下一项:

requests.post(url + 'sendPhoto', data={'chat_id': send_to_user_id}, files={'photo': open('/Users/abc/Desktop/webproject/kings/test_screenie1.png', 'rb')})

我已经在自己的漫游器上进行了本地测试,这种方法对我有效。

希望,为您服务。

相关问题