我有脚本可以通过日志系统打印出消息,或者有时打印命令。在 Windows 控制台上,我收到错误消息,例如
Traceback (most recent call last):
File "C:\Python32\lib\logging\__init__.py", line 939, in emit
stream.write(msg)
File "C:\Python32\lib\encodings\cp850.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_map)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u2019' in position 4537:character maps to <undefined>
是否有一种通用方法可以使日志系统、打印命令等中的所有编码都具有故障安全(忽略错误)?