unicodeencodeerror 'charmap' codec can't encode characters in position - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: unicodeencodeerror 'charmap' codec can't encode characters in position (/thread-1827.html) |
unicodeencodeerror 'charmap' codec can't encode characters in position - panoss - Jan-27-2017 The whole error is: "unicodeencodeerror 'charmap' codec can't encode characters in position 1-6: character maps to <undefined>" Appears when I run my program in the win console. When I run it through the PyCharm IDE it does not appear. The characters it's refering to, are non Latin characters. I tried with .encode('utf-8') and .decode('utf-8') and seems ok. Is this the 'proper' way to handle this? RE: unicodeencodeerror 'charmap' codec can't encode characters in position - Kebap - Jan-28-2017 That is not the whole error, which has multiple lines. Also please show a minimal running code example, that we can run to produce this error you see. RE: unicodeencodeerror 'charmap' codec can't encode characters in position - sparkz_alot - Jan-28-2017 By default, Windows does not use 'utf-8', it uses 'code pages'. Your Pycharm settings most likely tells it to use 'utf-8', whereas your command terminal defaults to a code page. The code page is determined by the locale you chose at Windows installation. These code pages are based on standards created prior to the currently accepted 'utf-8' (which is a subset of Unicode). When Windows does use Unicode, it is utf-16, when you want to use utf-8, Windows has a (rather crappy, imho) code page of 65001. A list of all Python supported code pages can be found at: Python main directory \Lib\encodings A good read is here : Unicode RE: unicodeencodeerror 'charmap' codec can't encode characters in position - snippsat - Jan-28-2017 You should post an example and python version is important. Quote:I tried with .encode('utf-8') and .decode('utf-8') and seems ok.From where? Use a better shell cmder. In cmd: C:\>which python 'which' is not recognized as an internal or external command, operable program or batch file. C:\>python -c "import sys; print(sys.stdout.encoding)" utf-8 C:\>python -c "print('Spicy jalapeño ? ? ? ? ')" Spicy jalapeño ? ? ? ? C:\>python -c "print('? ? ? ? ?')" ? ? ? ? ?The same in cmder: C:\ λ which python /c/python36/python C:\ λ python -c "import sys; print(sys.stdout.encoding)" utf-8 C:\ λ python -c "print('Spicy jalapeño ☂ ☃ ★ ☁')" Spicy jalapeño ☂ ☃ ★ ☁ C:\ λ python -c "print('♚ ✈ ☹ ☠ ☝')" ♚ ✈ ☹ ☠ ☝ |