I am trying to send a photo through my Telegram bot, but am getting an error. I have the file path of the photo on my computer. Maybe I am not putting the file path in correctly. The error I get is:
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated UXXXXXXXX escape`.
Which is referring to right before the path name. This is the code I have:
import requests
import json
bot_token = 'XXXXXX'
chat_id = "-100YYYYYY"
file = "C:UsersnameOneDriveDesktopCapture.PNG"
message = ('https://api.telegram.org/bot'+ bot_token + '/sendPhoto?chat_id='
+ chat_id + 'photo=' + file)
send = requests.get(message)
2
Answers
Here is how you should upload file using the telegram sendPhoto endpoint in python.
In reply to the answer, I used the above code, but the image quality is just bad and i cannot understand the images contents clearly. Image is of a screenshot of my laptop screen which has a 1080p resolution