By default, the Requests python library writes log messages to the console, along the lines of:Starting new HTTP connection (1): example.comhttp://example.com:80 "GET / HTTP/1.1" 200 606我通常对这些消息不感兴趣,因此想禁用它们.使这些消息静音或降低请求的冗长程度的最佳方法是什么?I'm usually not interested in these messages, and would like to disable them. What would be the best way to silence those messages or decrease Requests' verbosity?推荐答案我发现了如何配置请求的日志记录级别,这是通过标准的记录模块.我决定将其配置为不记录消息,除非它们至少是警告:I found out how to configure requests's logging level, it's done via the standard logging module. I decided to configure it to not log messages unless they are at least warnings:import logginglogging.getLogger("requests").setLevel(logging.WARNING)如果您也希望将此设置应用于urllib3库(通常由请求使用),请添加以下内容:If you wish to apply this setting for the urllib3 library (typically used by requests) too, add the following:logging.getLogger("urllib3").setLevel(logging.WARNING) 这篇关于如何禁用请求库中的日志消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-06 18:22