Python 警告过滤器未捕获 InsecurePlatformWarning

标签 python python-2.7 ssl urllib3

自此消息

lib/python2.7/site-packages/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. InsecurePlatformWarning

一直在充斥我的日志(是的,我知道这很重要,我最终会解决真正的问题!我保证!),我想添加一个过滤器让它只显示一次。 所以我添加了这个:

warnings.simplefilter(action='once', category=InsecurePlatformWarning, append=True)

但它不过滤任何东西。 当我这样做时:

warnings.simplefilter(action='once', append=True)

它对所有警告都这样做,这不是我想要的,但它表明代码确实正在执行并且过滤器本身确实有效。

我在类别方面做错了什么? 我不想禁用警告。我只想让这个特定警告暂时只显示一次。

谢谢!

最佳答案

尝试删除 append=True:

warnings.simplefilter(action='once', category=InsecurePlatformWarning)

urllib3代码already has default logging configuration .如果您使用 append=True,则默认配置会覆盖您的配置。

关于Python 警告过滤器未捕获 InsecurePlatformWarning,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31321854/

相关文章:

c++ - BOOST ASIO 加载带有密码的 key.pem

python - 典型的 Unicode 错误 : Sublime vs. Atom

Python - 从其他模块中的函数重新分配全局变量的最佳方法

python - 打开串行端口或使用 pyserial 从串行端口读取时遇到问题

python - 从 Pandas DataFrame 快速填充大型 Numpy 矩阵

python - 如果条件为真,则使用 python 代码发送邮件

python - 在打开的树莓派上运行 python 脚本

python - while 循环会执行多少次?

ssl - 使用 DCOS 负载均衡器设置 SSL 终止

ssl - 有没有办法强制 Jetty 只使用 HTTPS?