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

前端 未结 9 927
南方客
南方客 2020-11-27 09:06

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,
           


        
相关标签:
9条回答
  • 2020-11-27 09:48

    Why not using pyvmomi original function SmartConnectNoSSL. They added this function on June 14, 2016 and named it ConnectNoSSL, one day after they changed the name to SmartConnectNoSSL, use that instead of by passing the warning with unnecessary lines of code in your project?

    Provides a standard method for connecting to a specified server without SSL verification. Useful when connecting to servers with self-signed certificates or when you wish to ignore SSL altogether

    service_instance = connect.SmartConnectNoSSL(host=args.ip,
                                                 user=args.user,
                                                 pwd=args.password)
    
    0 讨论(0)
  • 2020-11-27 09:50

    This is the answer in 2017. urllib3 not a part of requests anymore

    import urllib3
    urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
    
    0 讨论(0)
  • 2020-11-27 09:56

    The accepted answer doesn't work if some package vendors it's own copy of urllib3, in which case this will still work:

    import warnings
    
    warnings.filterwarnings('ignore', message='Unverified HTTPS request')
    
    0 讨论(0)
提交回复
热议问题