diff --git a/clients.py b/clients.py index ee0ba2da..c3549a4e 100644 --- a/clients.py +++ b/clients.py @@ -189,10 +189,13 @@ async def connect(self): """Establishes a WebSocket connection using authentication.""" host = self.WS_BASE_URL + self.url_suffix auth_headers = self.request_headers("GET", self.url_suffix) - async with websockets.connect(host, additional_headers=auth_headers) as websocket: - self.ws = websocket - await self.on_open() - await self.handler() + self.ws = await websockets.connect( + host, + additional_headers=auth_headers, + ) + + await self.on_open() + await self.handler() async def on_open(self): """Callback when WebSocket connection is opened.""" @@ -231,4 +234,4 @@ async def on_error(self, error): async def on_close(self, close_status_code, close_msg): """Callback when WebSocket connection is closed.""" - print("WebSocket connection closed with code:", close_status_code, "and message:", close_msg) \ No newline at end of file + print("WebSocket connection closed with code:", close_status_code, "and message:", close_msg)