Python 3.1.1 bytes decode with replace bug

Joe JoeSalmeri at
Mon Oct 26 20:55:56 CET 2009

Thanks Benjamin for solving the mystery of where the cp437 usage was
coming from.

So b'\x80abc'.decode("utf-8", "replace") was working properly but then
when the interactive prompt tried to print it, it was basically taking
the results and doing a
encode('cp437', 'strict') which failed because of the characters that
are not part of cp437.

It might not be a bad idea to put a note on that documentation page
because I sure others will work though the samples like I did and if
they are on Windows run into the same issue.

> Try checking sys.stdout.encoding. Then run the command chcp (not in
> the python interpreter). You'll probably get 437 from both of those.
> Just because the system encoding is set to utf-8 doesn't mean the
> console is. Nobody really uses cp437 anymore- it was replaced years
> ago by cp1252- but Microsoft is scared to do anything to cmd.exe
> because it might break somebody's 20-year-old DOS script

More information about the Python-list mailing list