From ffeb39eeb34295ae095c59fdf9b1803abc2f28fc Mon Sep 17 00:00:00 2001 From: Fabian Topfstedt Date: Tue, 21 May 2024 09:36:11 +0200 Subject: [PATCH] Fix for Python 3.12 (ssl.wrap_socket is deprecated since 3.7 and got removed in 3.12; creating a default ssl context and using it to wrap the socket for 3.12+) --- hetzner/util/http.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/hetzner/util/http.py b/hetzner/util/http.py index a5e6789..1725e8a 100644 --- a/hetzner/util/http.py +++ b/hetzner/util/http.py @@ -63,8 +63,13 @@ def connect(self): ).encode('ascii')) ca_certs.flush() cafile = ca_certs.name - self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file, - cert_reqs=ssl.CERT_REQUIRED, - ca_certs=cafile) + if hasattr(ssl, "wrap_socket"): + self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file, + cert_reqs=ssl.CERT_REQUIRED, + ca_certs=cafile) + else: + ctx = ssl.create_default_context() + ctx.load_verify_locations(cafile=cafile) + self.sock = ctx.wrap_socket(sock, server_hostname=self.host) if bundle is None: ca_certs.close()