Python3 logger.info() 在 suse 上输出

2019-04-04  本文已影响0人  万事皆成

问题:
logger.info('测试')
报错:
UnicodeEncodeError: 'ascii' codec can't encode characters in position 48-49: ordinal not in range(256)

原因:
SuSE 下,Python3 logging 模块默认编码方式为: ISO-8859-1,只能输出 ASCII 码,需要改成 utf-8

解决方案:
设置logging 编码方式为 utf-8
logging.basicConfig(handlers=[logging.FileHandler(nombreFicheroLog, 'w', 'utf-8')],
level=logging.DEBUG)

参考:

How to encode log file?

上一篇 下一篇

猜你喜欢

热点阅读