2

I'm trying to upload a photo using telepot python library in a telegram bot.

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)

This code gives me this error:

telepot.exception.TelegramError: ('Bad Request: type of file mismatch', 400, {'ok': False, 'error_code': 400, 'description': 'Bad Request: type of file mismatch'})

If I try to access to the local file created by tempfile.mkstemp(), it exists and gives the correct image. I also tried specifying the extension of the image in the image name but there is still the same error.

Thanks for your help

Marco Castano
  • 1,114
  • 1
  • 10
  • 25

1 Answers1

1

I had this problem before, but in other prerequisites. I tried to specify fileId when sending the video, but that fileId was recognised as Document, rather than Video. I re-uploaded file as video, specified new fileId and it worked.

Dharman
  • 30,962
  • 25
  • 85
  • 135