Skip to content

Commit 083bcac

Browse files
committed
Import ConnectionClosed from websockets.exceptions.
Fix #1539.
1 parent e9fc77d commit 083bcac

File tree

5 files changed

+8
-5
lines changed

5 files changed

+8
-5
lines changed

docs/faq/client.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,12 @@ How do I reconnect when the connection drops?
8484
Use :func:`~websockets.asyncio.client.connect` as an asynchronous iterator::
8585

8686
from websockets.asyncio.client import connect
87+
from websockets.exceptions import ConnectionClosed
8788

8889
async for websocket in connect(...):
8990
try:
9091
...
91-
except websockets.ConnectionClosed:
92+
except ConnectionClosed:
9293
continue
9394

9495
Make sure you handle exceptions in the ``async for`` loop. Uncaught exceptions

docs/faq/server.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ Then, call :meth:`~ServerConnection.send`::
147147

148148
async def message_user(user_id, message):
149149
websocket = CONNECTIONS[user_id] # raises KeyError if user disconnected
150-
await websocket.send(message) # may raise websockets.ConnectionClosed
150+
await websocket.send(message) # may raise websockets.exceptions.ConnectionClosed
151151

152152
Add error handling according to the behavior you want if the user disconnected
153153
before the message could be sent.

docs/intro/tutorial1.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,13 @@ spot real errors when you add functionality to the server. Catch it in the
271271

272272
.. code-block:: python
273273
274+
from websockets.exceptions import ConnectionClosedOK
275+
274276
async def handler(websocket):
275277
while True:
276278
try:
277279
message = await websocket.recv()
278-
except websockets.ConnectionClosedOK:
280+
except ConnectionClosedOK:
279281
break
280282
print(message)
281283

src/websockets/asyncio/client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class connect:
182182
async for websocket in connect(...):
183183
try:
184184
...
185-
except websockets.ConnectionClosed:
185+
except websockets.exceptions.ConnectionClosed:
186186
continue
187187
188188
If the connection fails with a transient error, it is retried with

src/websockets/legacy/client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ class Connect:
349349
async for websocket in connect(...):
350350
try:
351351
...
352-
except websockets.ConnectionClosed:
352+
except websockets.exceptions.ConnectionClosed:
353353
continue
354354
355355
The connection is closed automatically after each iteration of the loop.

0 commit comments

Comments
 (0)