Working with self-signed vCenter certificates in an enterprise environment (such as RHEL 6 running mixed Python 2.6/2.7 and pyvmomi 5.5+) often leads to this error:
File "/usr/lib/python2.6/site-packages/requests/adapters.py", line 447, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: [Errno 1] _ssl.c:492: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
If you need a quick workaround to bypass certificate verification in development scripts:
import ssl
import requests
from pyVim.connect import SmartConnect
context = None
try:
# Disable SSL certificate verification via standard library
context = ssl.SSLContext(ssl.PROTOCOL_SSLv3)
context.verify_mode = ssl.CERT_NONE
except AttributeError:
# Fallback monkey-patch for older Python/requests environments
rget = requests.get
requests.get = lambda obj, *args, **kwargs: rget(obj, verify=False)
requests.packages.urllib3.disable_warnings()
# Connect to ESXi / vCenter
si = SmartConnect(
host=args.host,
user=user,
pwd=args.password,
port=int(args.port),
sslContext=context
)
This bypasses certificate validation issues so you can get back to writing your automation scripts.
(Note: For production environments, always ensure proper CA root certificates are installed).