--- request.py 2012-08-22 21:55:47.975739300 -0400 +++ request.py.new 2012-08-23 19:02:11.157409319 -0400 @@ -118,24 +118,22 @@ def urlopen(url, data=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, *, cafile=None, capath=None): global _opener + if _opener is None: + _opener = build_opener() if cafile or capath: if not _have_ssl: raise ValueError('SSL support not available') - context = ssl.SSLContext(ssl.PROTOCOL_SSLv23) - context.options |= ssl.OP_NO_SSLv2 - if cafile or capath: - context.verify_mode = ssl.CERT_REQUIRED - context.load_verify_locations(cafile, capath) - check_hostname = True - else: - check_hostname = False - https_handler = HTTPSHandler(context=context, check_hostname=check_hostname) - opener = build_opener(https_handler) - elif _opener is None: - _opener = opener = build_opener() - else: - opener = _opener - return opener.open(url, data, timeout) + for handler in _opener.handle_open['https']: + if isinstance(handler, HTTPSHandler): + if handler._context is None: + handler._context = ssl.SSLContext(ssl.PROTOCOL_SSLv23) + else: + handler._context.protocol = ssl.PROTOCOL_SSLv23 + handler._context.options |= ssl.OP_NO_SSLv2 + handler._context.verify_mode = ssl.CERT_REQUIRED + handler._context.load_verify_locations(cafile, capath) + handler._check_hostname = True + return _opener.open(url, data, timeout) def install_opener(opener): global _opener