gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 13:11:26 27 4
gpt4 key购买 nike

我试图抑制以下警告:

/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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com