Skip to content

Commit 37118fa

Browse files
authored
gh-94172: urllib.request avoids deprecated key_file/cert_file (#94232)
The urllib.request module no longer uses the deprecated key_file and cert_file parameter of the http.client module.
1 parent e87ada4 commit 37118fa

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

Lib/urllib/request.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1990,9 +1990,17 @@ def http_error_default(self, url, fp, errcode, errmsg, headers):
19901990

19911991
if _have_ssl:
19921992
def _https_connection(self, host):
1993-
return http.client.HTTPSConnection(host,
1994-
key_file=self.key_file,
1995-
cert_file=self.cert_file)
1993+
if self.key_file or self.cert_file:
1994+
http_version = http.client.HTTPSConnection._http_vsn
1995+
context = http.client._create_https_context(http_version)
1996+
context.load_cert_chain(self.cert_file, self.key_file)
1997+
# cert and key file means the user wants to authenticate.
1998+
# enable TLS 1.3 PHA implicitly even for custom contexts.
1999+
if context.post_handshake_auth is not None:
2000+
context.post_handshake_auth = True
2001+
else:
2002+
context = None
2003+
return http.client.HTTPSConnection(host, context=context)
19962004

19972005
def open_https(self, url, data=None):
19982006
"""Use HTTPS protocol."""

0 commit comments

Comments
 (0)