4

I'm using api.telegram.bot and requests to send messages and images.

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

This is working fine. My telegram user is able to receive the message "Messo".

Now, I'm trying to use sendPhoto to send an image that I have hosted on my local drive.

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

I do not get any exceptions, however, my user is not receiving the image. The output I get in Jupyter notebook is: <Response [414]>

My .ipynb file, where this code is running, is located in: /Users/abc/Desktop/webproject/play0.ipynb

My image file is located in: /Users/abc/Desktop/webproject/kings/test_screenie1.png

I am running this on Mac OS.

eyllanesc
  • 221,139
  • 17
  • 121
  • 189
Gen Tan
  • 738
  • 7
  • 20

1 Answers1

3

Please, try this one:

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

I have tested locally on my bot, this approach works for me.

Hope, works for you.

Artem Rys
  • 124
  • 9