UnicodeEncodeError: 'charmap' codec can't encode character… problems

前端 未结 2 1252
误落风尘
误落风尘 2020-12-19 14:11

Before anyone gives me crap about this being asked a billion times, please note that I\'ve tried several of the answers in many a thread but none of them seemed to work prop

相关标签:
2条回答
  • 2020-12-19 14:32

    What I ended up doing as a possible temporary fix (depending on if anyone have a better answer) was using Unidecode. Unfortunately I lost all the accents but maybe someone has a fix for that.

    0 讨论(0)
  • 2020-12-19 14:51

    Everything is fine up until the point where you try to print the string. To print a string it must first be converted from pure Unicode to the byte sequences supported by your output device. This requires an encode to the proper character set, which Python has identified as cp850 - the Windows Console default.

    Starting with Python 3.4 you can set the Windows console to use UTF-8 with the following command issued at the command prompt:

    chcp 65001
    

    This should fix your issue, as long as you've configured the window to use a font that contains the character.

    Starting with Python 3.6 this is no longer necessary - Windows has always had a full Unicode interface for the console, and Python is now using it in place of the primitive code page I/O. Unicode to the console just works.

    0 讨论(0)
提交回复
热议问题