R
R
Roman2020-06-17 10:00:02
Python
Roman, 2020-06-17 10:00:02

How to send a video via telegram bot if there is an error related to the encoding?

I have an idea in my head to write a program that will download videos from the site and send a bot via telegram. I download the file through the requests library, it has the ".ts" extension, but there is a problem with sending
Code:

receive=open('file.ts', 'r')
bot.send_video('id', receive)
receive.close()


Mistake:
Traceback (most recent call last):
  File "1.py", line 9, in <module>
    bot.send_video('id', receive)
  File "C:\Users\Roman\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\__init__.py", line 733, in send_video
    apihelper.send_video(self.token, chat_id, data, duration, caption, reply_to_message_id, reply_markup,
  File "C:\Users\Roman\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\apihelper.py", line 397, in send_video
    return _make_request(token, method_url, params=payload, files=files, method='post')
  File "C:\Users\Roman\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\apihelper.py", line 57, in _make_request
    result = _get_req_session().request(method, request_url, params=params, files=files,
  File "C:\Users\Roman\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\sessions.py", line 516, in request
    prep = self.prepare_request(req)
  File "C:\Users\Roman\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\sessions.py", line 449, in prepare_request
    p.prepare(
  File "C:\Users\Roman\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\models.py", line 317, in prepare
    self.prepare_body(data, files, json)
  File "C:\Users\Roman\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\models.py", line 505, in prepare_body
    (body, content_type) = self._encode_files(files, data)
  File "C:\Users\Roman\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\models.py", line 159, in _encode_files
    fdata = fp.read()
  File "C:\Users\Roman\AppData\Local\Programs\Python\Python38-32\lib\encodings\cp1251.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x98 in position 959: character maps to <undefined>


With files of the extension ".mp4" the same trouble.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question