Python - 禁用 SecurityWarning : Certificate has no `subjectAltName` , RFC 2818 的警告

标签 python

我试图抑制以下警告:

/usr/lib/python2.7/site-packages/urllib3/connection.py:251: SecurityWarning: Certificate has no `subjectAltName`, falling back to check for a `commonName` for now. This feature is being removed by major browsers and deprecated by RFC 2818. (See https://github.com/shazow/urllib3/issues/497 for details.)
  SecurityWarning

我的代码如下

import requests
from orionsdk import SwisClient

#solarwinds creds
hostname = 'SolarWinds-Orion'
username = 'api'
password = 'XXXX'
v_path = '/var/www/itapp/tools/solarwinds.pem'

sites = SiteData.objects.exclude(site_type='Major Site').filter(is_live=True)
swis = SwisClient(hostname, username, password, verify=v_path)

query = """
    SELECT NodeID
          ,NodeName
          ,IPAddress
    FROM Orion.Nodes 
    WHERE NodeName LIKE '%NVR'
"""
requests.packages.urllib3.disable_warnings()
existing_results = swis.query(query)
nodes = existing_results["results"]

我的搜索显示,如果我发出 requests.packages.urllib3.disable_warnings(),那么警告应该被抑制,但无论我把那行放在哪里,我总是会收到警告。 我是否遗漏了什么或者我需要使用其他东西吗?

谢谢

最佳答案

嗯,如果我没记错的话,requests 使用它自己销售的 urllib3 副本,但您收到的警告直接来自您安装的 urllib3 副本。

尝试做:

import urllib3
urllib3.disable_warnings(urllib3.exceptions.SecurityWarning)

您还可以处理 warnings 生成的任何类型的警告像这样的 python 库:

import warnings
warnings.simplefilter('ignore', urllib3.exceptions.SecurityWarning)

关于Python - 禁用 SecurityWarning : Certificate has no `subjectAltName` , RFC 2818 的警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42839363/

相关文章:

python - "Why are the cosine similarities calculated by the library and by myself different?"

python - 使用 python matplotlib 在 3d 图中均匀缩放轴

python - 使用 Matplotlib 处理缩放时在两个子图之间绘制一条线

python - 如何生成满足某些条件的三个随机整数?

python - 无 float 伪影的轮廓

python - rbf 和 scipy 的二维概率分布

python - 如何获得线性下降随机分布?

python - 如何从 pandas 的一列中获取不包含在另一列中的 id 列表

python - 在导入的模块中使用外部类方法

python - 用循环交换列表