From f70fe0d76f1e12ab4860a84a637db85b565a6b09 Mon Sep 17 00:00:00 2001 From: Dr Maurice Hendrix Date: Wed, 12 Mar 2025 14:52:44 +0100 Subject: [PATCH 1/2] Update s2_connection.py When using an unsecure connection an error was thrown that the ssl parameter is incompatible with ws://. This PR adds a workaround to still allow non wss connections --- src/s2python/s2_connection.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/s2python/s2_connection.py b/src/s2python/s2_connection.py index 035d118..c6fcc2a 100644 --- a/src/s2python/s2_connection.py +++ b/src/s2python/s2_connection.py @@ -322,13 +322,14 @@ async def wait_till_connection_restart() -> None: await self.ws.wait_closed() async def _connect_ws(self) -> None: - ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) - if not self._verify_certificate: - ssl_context.check_hostname = False - ssl_context.verify_mode = ssl.CERT_NONE - try: - self.ws = await ws_connect(uri=self.url, ssl=ssl_context) + if self.url.startswith("wss://") and not self._verify_certificate: + ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) + ssl_context.check_hostname = False + ssl_context.verify_mode = ssl.CERT_NONE + self.ws = await ws_connect(uri=self.url, ssl=ssl_context) + else: + self.ws = await ws_connect(uri=self.url) except (EOFError, OSError) as e: logger.info("Could not connect due to: %s", str(e)) From 3439aa41eb095b93527b14df65b263e30d100fb1 Mon Sep 17 00:00:00 2001 From: Dr Maurice Hendrix Date: Wed, 12 Mar 2025 14:55:45 +0100 Subject: [PATCH 2/2] Update s2_connection.py removed extra whitespace --- src/s2python/s2_connection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/s2python/s2_connection.py b/src/s2python/s2_connection.py index c6fcc2a..b9ec62c 100644 --- a/src/s2python/s2_connection.py +++ b/src/s2python/s2_connection.py @@ -326,7 +326,7 @@ async def _connect_ws(self) -> None: if self.url.startswith("wss://") and not self._verify_certificate: ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) ssl_context.check_hostname = False - ssl_context.verify_mode = ssl.CERT_NONE + ssl_context.verify_mode = ssl.CERT_NONE self.ws = await ws_connect(uri=self.url, ssl=ssl_context) else: self.ws = await ws_connect(uri=self.url)