【发布时间】:2018-03-20 01:24:18
【问题描述】:
在 Windows 10 上,日志记录模块发送此错误(使用 scrapy)
# --- Logging error ---
...
# UnicodeEncodeError: 'charmap' codec can't encode characters in position 175-176: character maps to <undefined>
我已经读到我应该添加 编辑:根据the tuto,它不需要。 encoding='utf-8',但我没有找到如何在下面的代码中添加它。
configure_logging(install_root_handler=False) #override default log settings
logging.basicConfig(
filename='logfile.log',
format='%(levelname)s: %(message)s',
datefmt='%m-%d %H:%M',
level=logging.INFO #CRITICAL ERROR WARNING INFO DEBUG NOTSET
)
我发现了很多关于这些主题的问题,但主要是关于 python 2(或not related to the logging module)。日志教程甚至不谈论 utf-8。 (请注意,我可以毫无问题地打印 UTF8 字符。问题仅出现在日志记录模块上)
【问题讨论】:
标签: python-3.x logging encoding character-encoding error-logging