I'm having some issues with python encoding. When I try to execute this:
subprocess.check_output("ipconfig", shell=True)
it gives me an output with special characters in it, like:
"Statut du m\x82dia"
"M\x82dia d\x82connect\x82"
(i'm french)
When I try decoding it with a .decode()
at the end, it gives me this error:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x82 in position 78: invalid start byte
I tried using .decode("utf-8")
, I played around with encoding and decoding for hours, and I can't find the answer. Everything I looked on the internet didn't work. Maybe I'm just dumb, but hey.
What can I do to get rid of those decoding errors and get my special characters to be printed?
Thanks.
You're invoking the command through CMD, which has a Unicode mode and an ANSI mode. The "correct" way is to invoke the Unicode mode, but you can add encoding="437"
or encoding="850"
to the subprocess call to make it work. This depends on you knowing what the current codepage is.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With