Skip to content

Commit

Permalink
gh-94172: urllib.request avoids deprecated key_file/cert_file (#94232)
Browse files Browse the repository at this point in the history
The urllib.request module no longer uses the deprecated key_file and
cert_file parameter of the http.client module.
  • Loading branch information
vstinner committed Jun 26, 2022
1 parent e87ada4 commit 37118fa
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions Lib/urllib/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -1990,9 +1990,17 @@ def http_error_default(self, url, fp, errcode, errmsg, headers):

if _have_ssl:
def _https_connection(self, host):
return http.client.HTTPSConnection(host,
key_file=self.key_file,
cert_file=self.cert_file)
if self.key_file or self.cert_file:
http_version = http.client.HTTPSConnection._http_vsn
context = http.client._create_https_context(http_version)
context.load_cert_chain(self.cert_file, self.key_file)
# cert and key file means the user wants to authenticate.
# enable TLS 1.3 PHA implicitly even for custom contexts.
if context.post_handshake_auth is not None:
context.post_handshake_auth = True
else:
context = None
return http.client.HTTPSConnection(host, context=context)

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

0 comments on commit 37118fa

Please sign in to comment.