Fix bug in BfxWebsocketClient::close (bfxapi.websocket.client.bfx_websocket_client).

This commit is contained in:
Davide Casale
2023-04-16 21:16:18 +02:00
parent 6d868a8287
commit e15b52eabd
2 changed files with 7 additions and 7 deletions

View File

@@ -61,7 +61,7 @@ class BfxWebsocketBucket:
try:
await _connection()
except websockets.ConnectionClosedError as error:
except websockets.exceptions.ConnectionClosedError as error:
if error.code in (1006, 1012):
self.on_open_event.clear()

View File

@@ -152,7 +152,7 @@ class BfxWebsocketClient:
rcvd = websockets.frames.Close(code=1012,
reason="Stop/Restart Websocket Server (please reconnect).")
raise websockets.ConnectionClosedError(rcvd=rcvd, sent=None)
raise websockets.exceptions.ConnectionClosedError(rcvd=rcvd, sent=None)
elif message["event"] == "auth":
if message["status"] != "OK":
raise InvalidAuthenticationCredentials(
@@ -177,8 +177,8 @@ class BfxWebsocketClient:
try:
await _connection()
except (websockets.ConnectionClosedError, socket.gaierror) as error:
if isinstance(error, websockets.ConnectionClosedError) and error.code in (1006, 1012):
except (websockets.exceptions.ConnectionClosedError, socket.gaierror) as error:
if isinstance(error, websockets.exceptions.ConnectionClosedError) and error.code in (1006, 1012):
if error.code == 1006:
self.logger.error("Connection lost: no close frame received " \
"or sent (1006). Attempting to reconnect...")
@@ -235,12 +235,12 @@ class BfxWebsocketClient:
await bucket.unsubscribe(chan_id=chan_id)
async def close(self, code=1000, reason=str()):
if self.websocket is not None and self.websocket.open:
await self.websocket.close(code=code, reason=reason)
for bucket in self.buckets:
await bucket.close(code=code, reason=reason)
if self.websocket is not None and self.websocket.open:
await self.websocket.close(code=code, reason=reason)
@_require_websocket_authentication
async def notify(self, info, message_id=None, **kwargs):
await self.websocket.send(json.dumps([ 0, "n", message_id, { "type": "ucm-test", "info": info, **kwargs } ]))