mpgn
mpgn

Reputation: 7251

Decode french accent not working with utf-8

I try to decode this very simple variable b'autorite nt\\syst\x8ame\r\n'

b'autorite nt\\syst\x8ame\r\n'
>>> t.decode('utf-8')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8a in position 16: invalid start byte

But nothing is working, it should print autorite nt\\système but I cannot find a way to print it correctly

Upvotes: 0

Views: 1295

Answers (2)

jai
jai

Reputation: 112

You can use decode with utf-8 encoding and replacement rule.

t = b'autorite nt\\syst\x8ame\r\n'
t.decode('utf-8', 'replace')

Further reading: https://docs.python.org/3/howto/unicode.html

Upvotes: 0

snakecharmerb
snakecharmerb

Reputation: 55913

It isn't encoded as UTF-8. It might be cp437, or any of these: cp437, cp720, cp850, cp857, cp858, cp860, cp861, cp863, cp865 (source)

>>> print(b'autorite nt\\syst\x8ame\r\n'.decode('cp437'))
autorite nt\système

Upvotes: 2

Related Questions