我正在使用 iptcinfo Python 模块从图片中获取元数据,但它向我抛出了很多此类(无用的)警告:
('警告:字符集识别问题', "'\x1b'")
这是什么意思,我该如何删除这些警告(或防止它们发生),因为它们似乎对我的代码不重要?
我的代码很简单:
import iptcinfo
iptc = iptcinfo.IPTCInfo("DSC05647.jpg")
请您参考如下方法:
This line in the code似乎正在生成警告:
LOG.warn('problems with charset recognition %s', repr(temp))
您看到此消息是因为 Python 日志记录模块的默认日志记录级别是“警告”。
在您的代码中,您可以修改库的记录器的 logging level更高,这样你就不会看到警告:
import logging
iptcinfo_logger = logging.getLogger('iptcinfo')
iptcinfo_logger.setLevel(logging.ERROR)
编辑:为了进行故障排除,这里有一个片段可以查看每个记录器的级别:
for logger_name in logging.Logger.manager.loggerDict:
logger_level = logging.getLogger(logger_name).level
print logger_name, logging.getLevelName(logger_level)
