Suppress InsecureRequestWarning: Unverified HTTPS request is being made in Python2.6

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.

Update (2017-07-28): If you're using a modern version of these libraries, they may no longer be vendored. If that's the case, then you'll only need to do:

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

If you're still using a version of Requests which vendors urllib3 inside of it (like the original question), then you can use the 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)

From: stackoverflow.com/q/27981545

Back to homepage or read more recommendations: