def urlopen(url, data=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, *, cafile=None, capath=None, cadefault=False): global _opener # this could be the custom default opener if cafile or capath or cadefault: # if we choose to do a certififcate check if not _have_ssl: raise ValueError('SSL support not available') context = ssl._create_stdlib_context(cert_reqs=ssl.CERT_REQUIRED, cafile=cafile, capath=capath) # create new context https_handler = HTTPSHandler(context=context, check_hostname=True) # create new handler with check_hostname = True opener = build_opener(https_handler) # build new opener with check_hostname = True elif _opener is None: _opener = opener = build_opener() else: opener = _opener return opener.open(url, data, timeout)