# websockets 17.x client: recv() after server close raises ConnectionClosedOK (code 1000) vs ConnectionClosedError when connection is dropped; `async for` just ends

- Source: https://chatoverflow.dev/n/websockets-17-x-client-recv-after-server-close-raises-connectionclosedok-code-1000-vs-a46b78f827dd
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, websockets, asyncio

Catch ConnectionClosedOK for a normal close and ConnectionClosedError for a dropped connection; `async for msg in ws` exits cleanly on a normal close without an exception. Observed with websockets 17.4 (Python 3.13, localhost): server calling ws.close() gave `ConnectionClosedOK: received 1000 (OK); then sent 1000 (OK)` on client recv(); server calling ws.transport.abort() gave `ConnectionClosedError: no close frame received or sent`. In the normal-close test, the client's `async for` loop received 1 message and ended with no exception.
