summaryrefslogtreecommitdiffstats
path: root/Lib/urllib
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-06-24 15:45:28 (GMT)
committerGitHub <noreply@github.com>2022-06-24 15:45:28 (GMT)
commitf0b234e6ed83e810bd9844e744f5e22aa538a356 (patch)
tree7bfb542d0c120c3f48b1e607bd10185ad00718f6 /Lib/urllib
parente69306f08b9be84ccdd0a1c6601ec229c4e5b377 (diff)
downloadcpython-f0b234e6ed83e810bd9844e744f5e22aa538a356.zip
cpython-f0b234e6ed83e810bd9844e744f5e22aa538a356.tar.gz
cpython-f0b234e6ed83e810bd9844e744f5e22aa538a356.tar.bz2
gh-94172: urllib.request avoids deprecated check_hostname (#94193)
The urllib.request no longer uses the deprecated check_hostname parameter of the http.client module. Add private http.client._create_https_context() helper to http.client, used by urllib.request. Remove the now redundant check on check_hostname and verify_mode in http.client: the SSLContext.check_hostname setter already implements the check.
Diffstat (limited to 'Lib/urllib')
-rw-r--r--Lib/urllib/request.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py
index c352fb2..7878daa 100644
--- a/Lib/urllib/request.py
+++ b/Lib/urllib/request.py
@@ -1383,12 +1383,16 @@ if hasattr(http.client, 'HTTPSConnection'):
def __init__(self, debuglevel=0, context=None, check_hostname=None):
AbstractHTTPHandler.__init__(self, debuglevel)
+ if context is None:
+ http_version = http.client.HTTPSConnection._http_vsn
+ context = http.client._create_https_context(http_version)
+ if check_hostname is not None:
+ context.check_hostname = check_hostname
self._context = context
- self._check_hostname = check_hostname
def https_open(self, req):
return self.do_open(http.client.HTTPSConnection, req,
- context=self._context, check_hostname=self._check_hostname)
+ context=self._context)
https_request = AbstractHTTPHandler.do_request_