S
S
Samosh20102021-09-05 19:50:31
Python
Samosh2010, 2021-09-05 19:50:31

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 382: invalid start byte, what to do?

subprocess is trying to execute the command and output the result, but then display an error:

def execute(command):
    return subprocess.check_output(command, shell = True, encoding = 'utf-8')

Traceback (most recent call last):
  File "C:\Users\maksa\Desktop\My Files\vidstream\client.py", line 34, in <module>
    result = execute(cmd_data)
  File "C:\Users\maksa\Desktop\My Files\vidstream\client.py", line 17, in execute
    return subprocess.check_output(command, shell = True, encoding = 'utf-8')
  File "C:\Program Files\Python39\lib\subprocess.py", line 424, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "C:\Program Files\Python39\lib\subprocess.py", line 507, in run
    stdout, stderr = process.communicate(input, timeout=timeout)
  File "C:\Program Files\Python39\lib\subprocess.py", line 1121, in communicate
    stdout = self.stdout.read()
  File "C:\Program Files\Python39\lib\codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 382: invalid start byte

what is the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GH0st_is_HAcker, 2021-09-05
@Samosh2010

Try to add after

return subprocess.check_output(command, shell = True, encoding = 'utf-8')

This: Just remove it As a result, you should get:
.content.decode('Windows-1251')
def execute(command):
    return subprocess.check_output(command, shell = True).content.decode('Windows-1251')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question