禁止不安全请求警告:在Python2.6中正在进行未验证的HTTPS请求(Suppress InsecureRequestWarning: Unverified HTTPS request is be

编程入门 行业动态 更新时间:2024-10-25 10:32:16
禁止不安全请求警告:在Python2.6中正在进行未验证的HTTPS请求(Suppress InsecureRequestWarning: Unverified HTTPS request is being made in Python2.6)

我在Python2.6中使用pyVmomi和使用其中一种连接方式编写脚本:

service_instance = connect.SmartConnect(host=args.ip, user=args.user, pwd=args.password)

我收到以下警告:

/usr/lib/python2.6/site-packages/requests/packages/urllib3/connectionpool.py:734: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html InsecureRequestWarning)

有趣的是,我没有使用pip安装urllib3(但是它在/usr/lib/python2.6/site-packages/requests/packages/urllib3/中 )。

我试过这里建议

import urllib3 ... urllib3.disable_warnings()

但这并没有改变任何事情。

I am writing scripts in Python2.6 with use of pyVmomi and while using one of the connection methods:

service_instance = connect.SmartConnect(host=args.ip, user=args.user, pwd=args.password)

I get the following warning:

/usr/lib/python2.6/site-packages/requests/packages/urllib3/connectionpool.py:734: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html InsecureRequestWarning)

What's interesting is that I do not have urllib3 installed with pip (but it's there in /usr/lib/python2.6/site-packages/requests/packages/urllib3/).

I have tried as suggested here

import urllib3 ... urllib3.disable_warnings()

but that didn't change anything.

最满意答案

更新(2017-07-28):如果您使用这些库的现代版本,它们可能不再被销毁。 如果是这样,那么你只需要做:

import urllib3 urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

如果您仍然在其中使用一个供应商urllib3的请求版本(如原始问题),则可以使用以下原始答案:

原来的答案:

做urllib3.disable_warnings()没有为你工作的原因是因为它看起来像是在请求内部使用一个单独的urllib3实例。

我根据以下路径收集: /usr/lib/python2.6/site-packages/requests/packages/urllib3/connectionpool.py

要在请求的vendire urllib3中禁用警告,您需要导入该模块的特定实例:

import requests from requests.packages.urllib3.exceptions import InsecureRequestWarning requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

You can disable any Python warnings via the PYTHONWARNINGS environment variable. In this case, you want:

export PYTHONWARNINGS="ignore:Unverified HTTPS request"

To disable using Python code (requests >= 2.16.0):

import urllib3 urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

For requests < 2.16.0, see original answer below.

Original answer

The reason doing urllib3.disable_warnings() didn't work for you is because it looks like you're using a separate instance of urllib3 vendored inside of requests.

I gather this based on the path here: /usr/lib/python2.6/site-packages/requests/packages/urllib3/connectionpool.py

To disable warnings in requests' vendored urllib3, you'll need to import that specific instance of the module:

import requests from requests.packages.urllib3.exceptions import InsecureRequestWarning requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

更多推荐

本文发布于:2023-08-07 18:46:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465123.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:正在进行   不安全   HTTPS   request   Unverified

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!