我正在尝试在电报机器人中使用 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() 创建的本地文件,它会存在并提供正确的图像。我还尝试在图像名称中指定图像的扩展名,但仍然存在相同的错误。
谢谢你的帮助