pyvmomi: How do I disable the SSL cert check? --> connect.SmartConnect fails with SSL: CERTIFICATE_VERIFY_FAILED error -- h

connect.SmartConnect fails with SSL error – how do I disable the SSL cert check?

Run on Python 3.5.2 :: Anaconda 4.1.1 (x86_64)

>>> from pyvim import connect
>>> from pyVmomi import vmidl
>>> from pyVmomi import vim
>>> si = connect.SmartConnect(host=inputs['vcenter_ip'], port=443, user=inputs['vcenter_user'], pwd=inputs['vcenter_password'], service="hosted"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/jsmith/anaconda3/lib/python3.5/site-packages/pyvim/connect.py", line 786, in SmartConnect
    sslContext)
  File "/Users/jsmith/anaconda3/lib/python3.5/site-packages/pyvim/connect.py", line 671, in __FindSupportedVersion
    sslContext)
  File "/Users/jsmith/anaconda3/lib/python3.5/site-packages/pyvim/connect.py", line 591, in __GetServiceVersionDescription
    path + "/vimServiceVersions.xml", sslContext)
  File "/Users/jsmith/anaconda3/lib/python3.5/site-packages/pyvim/connect.py", line 557, in __GetElementTree
    conn.request("GET", path)
  File "/Users/jsmith/anaconda3/lib/python3.5/http/client.py", line 1106, in request
    self._send_request(method, url, body, headers)
  File "/Users/jsmith/anaconda3/lib/python3.5/http/client.py", line 1151, in _send_request
    self.endheaders(body)
  File "/Users/jsmith/anaconda3/lib/python3.5/http/client.py", line 1102, in end headers
    self._send_output(message_body)
  File "/Users/jsmith/anaconda3/lib/python3.5/http/client.py", line 934, in _send_output
    self.send(msg)
  File "/Users/jsmith/anaconda3/lib/python3.5/http/client.py", line 877, in send
    self.connect()
  File "/Users/jsmith/anaconda3/lib/python3.5/http/client.py", line 1260, in connect
    server_hostname=server_hostname)
  File "/Users/jsmith/anaconda3/lib/python3.5/ssl.py", line 377, in wrap_socket
    _context=self)
  File "/Users/jsmith/anaconda3/lib/python3.5/ssl.py", line 752, in __init__
    self.do_handshake()
  File "/Users/jsmith/anaconda3/lib/python3.5/ssl.py", line 988, in do_handshake
    self._sslobj.do_handshake()
  File "/Users/jsmith/anaconda3/lib/python3.5/ssl.py", line 633, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:645)
```)

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 18

Most upvoted comments

Use SmartConnectNoSSL to bypass SSL check,

 service_instance = connect.SmartConnectNoSSL(host=args.host,
                               user=args.user,
                               pwd=args.password,
                               port=int(args.port))

Use “requests” package.

import requests

# Write this line before creating pyVmomi session
requests.packages.urllib3.disable_warnings()

Meh, you really should have at least internal CA and valid certs for pyvmomi to use. All instructions thus far seem to be about disabling MITM protection for pyvmomi.

you can also… import ssl context = ssl._create_unverified_context()

si = SmartConnect(host=args.host, user=args.user, pwd=args.password, sslContext=context)

Hi

Please import urllib and disable the sslverify property at start of you code

Cheers

On Oct 4, 2017 7:49 PM, “Andy4081” notifications@github.com wrote:

Hi guys, I am very new to Python world. My goal is to collect VMs info (like CPU, RAM usage) from ESXi and was using this link as reference https://virtualwires.wordpress.com/2016/07/25/ using-pyvmomi-to-collect-esxi-info

I have both python 2.7 and 3.5 running on Ubuntu box:

root@ubuntu:~$ python3 --version Python 3.5.2 root@ubuntu:~$ python –version Python 2.7.12

When I run the script using Python 2.7, it gives “SSL: CERTIFICATE_VERIFY_FAILED” error like below: root@ubuntu:~$ python esx.py -s ‘Host_IP’ -u ‘user’ -p ‘pwd’ Traceback (most recent call last): File “esx.py”, line 33, in <module> main() File “esx.py”, line 19, in main si = SmartConnect(host=opts.shost, user=opts.username,pwd=opts.password ) … … conn.request(“GET”, path) File “/usr/lib/python2.7/httplib.py”, line 1057, in request self._send_request(method, url, body, headers) File “/usr/lib/python2.7/httplib.py”, line 1097, in _send_request self.endheaders(body) File “/usr/lib/python2.7/httplib.py”, line 1053, in endheaders self._send_output(message_body) File “/usr/lib/python2.7/httplib.py”, line 897, in _send_output self.send(msg) File “/usr/lib/python2.7/httplib.py”, line 859, in send self.connect() File “/usr/lib/python2.7/httplib.py”, line 1278, in connect server_hostname=server_hostname) File “/usr/lib/python2.7/ssl.py”, line 353, in wrap_socket _context=self) File “/usr/lib/python2.7/ssl.py”, line 601, in init self.do_handshake() File “/usr/lib/python2.7/ssl.py”, line 830, in do_handshake self._sslobj.do_handshake() ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590) root@ubuntu:~$

When I run using Python3 I get syntax error: root@ubuntu:~$ python3 esx.py -s ‘Host_IP’ -u ‘user’ -p ‘pwd’ File “esx.py”, line 25 print ‘The CPU vendor is %s and the model is %s’ %(cpuobj.vendor,cpuobj.description) ^ SyntaxError: invalid syntax root@ubuntu:~$

The script is the same as shown in the article - https://virtualwires.wordpress.com/2016/07/25/ using-pyvmomi-to-collect-esxi-info

How do I make it work?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/vmware/pyvmomi/issues/454#issuecomment-334253653, or mute the thread https://github.com/notifications/unsubscribe-auth/AM2peD7zGRkMVKTS4BEDNndH8l-bOhk7ks5so9MdgaJpZM4KFe0K .

python getallvms.py -s hostname -u username -p password -S did the trick for me .