diff --git a/uvicorn/protocols/websockets/wsproto_impl.py b/uvicorn/protocols/websockets/wsproto_impl.py index 35f88a720..bc9651fe7 100644 --- a/uvicorn/protocols/websockets/wsproto_impl.py +++ b/uvicorn/protocols/websockets/wsproto_impl.py @@ -91,7 +91,9 @@ def data_received(self, data): self.transport.write(self.conn.send(err.event_hint)) self.transport.close() else: - self.handle_no_connect(events.CloseConnection(code=1007)) + # Response with the "1002 Protocol Error" code. + # See https://www.iana.org/assignments/websocket/websocket.xhtml#close-code-number + self.handle_no_connect(events.CloseConnection(code=1002)) else: self.handle_events()