How to Fix SSL issues with pyvmomi and python 2.7.9

As many of you may or may not know there were some significant changes with regards to SSL in python 2.7.9 which introduce a default verify ssl cert where in the past it was ignored. This creates one hell of a problem when using pyVmomi because 99% of us use the default self signed certs created during the install process of our vCenters or ESXi systems. This problem has been reported a few times now. I answered the question on the mailing list of how to work around the problem, but figured I would add it here as well because there is so much confusion over how to work around the problem until we are able to get upstream pyVmomi patched up.

To work around this issue:

import requests

import ssl

    _create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
    # Legacy Python that doesn't verify HTTPS certificates by default
    # Handle target environment that doesn't support HTTPS verification
    ssl._create_default_https_context = _create_unverified_https_context

Add this to your scripts or tools that need to connect. This will make your scripts continue to work like they did on 2.7.8 and older where the default was to ignore the cert and not check it. I hope to see a fix added to upstream pyVmomi soon.