【发布时间】:2020-08-11 11:32:57
【问题描述】:
我正在尝试在电报机器人中使用 Telepot python 库上传照片。
fd, path = tempfile.mkstemp()
image_bytes = requests.get(url=fileUrl, stream=True)
with open(path, 'wb') as strm:
for chunk in image_bytes:
strm.write(chunk)
photoFile = open(path, mode='rb')
fileId = bot.sendPhoto(chat_id='chat_id', photo=photoFile)
这段代码给了我这个错误:
telepot.exception.TelegramError: ('Bad Request: type of file mismatch', 400, {'ok': False, 'error_code': 400, 'description': 'Bad Request: type of file mismatch'})
如果我尝试访问由 tempfile.mkstemp() 创建的本地文件,它会存在并提供正确的图像。 我也试过在图片名称中指定图片的扩展名,但还是一样的错误。
感谢您的帮助
【问题讨论】:
标签: python image bots telegram telepot