Use SSLContext.wrap_context() for SSL/TLS sockets

ssl.wrap_context() has been deprecated for some time, and has now been
removed. Use the newer API instead.
This commit is contained in:
Pierre Ossman 2024-07-30 09:16:27 +02:00
parent f05cd203de
commit f632fa0285
2 changed files with 4 additions and 2 deletions

View File

@ -139,7 +139,8 @@ class WebSocket(object):
self.socket = socket.create_connection((uri.hostname, port))
if uri.scheme in ("wss", "https"):
self.socket = ssl.wrap_socket(self.socket)
context = ssl.create_default_context()
self.socket = context.wrap_socket(self.socket)
self._state = "ssl_handshake"
else:
self._state = "headers"

View File

@ -470,7 +470,8 @@ class WebSockifyServer():
if connect:
sock.connect(addrs[0][4])
if use_ssl:
sock = ssl.wrap_socket(sock)
context = ssl.create_default_context()
sock = context.wrap_socket(sock)
else:
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind(addrs[0][4])