Fixing python error: ‘charmap’ codec can’t decode byte 0x9d in position 12180: character maps to

When running python code, you can get unicode errors like so:

'charmap' codec can't decode byte 0x9d in position 12180: character maps to 
'charmap' codec can't encode character '\u2019' in position 305: character maps to 

If this comes from reading a file, you can check the file’s encoding and change how you read the file:

$ file -i talk200.html
talk200.html: text/html; charset=utf-8
open(file, encoding="utf-8")

This also can happen if the terminal window can’t display unicode characters. If you’re using Visual Studio or the Windows Command prompt, the best option is to switch to something better, like iPython Notebook / QtConsole.

Leave a Reply

Your email address will not be published. Required fields are marked *