在Windows 10上,日志模块发送了这个错误(使用scrapy)
# --- Logging error ---
...
# UnicodeEncodeError: 'charmap' codec can't encode characters in position 175-176: character maps to <undefined>
我读到过应该添加编辑:根据教程,这不是必需的。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的(或与日志模块无关)。而且日志教程甚至不提及UTF-8。(请注意,我可以轻松地打印UTF8字符。问题仅出现在日志模块中)
logging.basicConfig()
的答案对我无效。 - SomJuraconfigure_logging()
的调用)。 - smsearcylogging.basicConfig()
的例子,我不确定带有configure_logging()
的第一行在那里做什么,如果你将其删除会发生什么?你需要import logging
。 - smsearcy