我试图通过我的Telegram机器人发送一张照片,但我收到了一个错误。我的电脑上有照片的文件路径。也许我没有正确输入文件路径。我得到的错误是:
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape`. 它就在路径名之前引用。这是我的代码:
import requests
import json
bot_token = 'XXXXXX'
chat_id = "-100YYYYYY"
file = "C:\Users\name\OneDrive\Desktop\Capture.PNG"
message = ('https://api.telegram.org/bot'+ bot_token + '/sendPhoto?chat_id='
+ chat_id + 'photo=' + file)
send = requests.get(message)发布于 2020-04-28 00:45:08
下面是如何使用python中的电报sendPhoto端点上传文件。
import requests
import json
bot_token = 'BOT TOKEN'
chat_id = "CHAT ID"
file = r"C:\Users\name\OneDrive\Desktop\Capture.PNG"
files = {
'photo': open(file, 'rb')
}
message = ('https://api.telegram.org/bot'+ bot_token + '/sendPhoto?chat_id='
+ chat_id)
send = requests.post(message, files = files)发布于 2020-08-12 13:21:33
作为回答,我使用了上面的代码,但图像质量很差,我不能清楚地理解图像内容。这是我的笔记本电脑屏幕截图,分辨率为1080p
https://stackoverflow.com/questions/61463102
复制相似问题