python
runtime_error
ai_generated
true
RuntimeError: Invalid close code: 1006
ID: python/starlette-invalid-websocket-close-code
80%Fix Rate
83%Confidence
0Evidence
2024-06-10First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
WebSocket关闭代码1006是协议保留值,不允许应用层使用
generic中文
WebSocket关闭代码1006是协议保留值,不允许应用层使用
Workarounds
-
95% success 使用合法的关闭代码(如1000正常关闭)
await websocket.close(code=1000)
-
90% success 使用自定义代码4000-4999范围
await websocket.close(code=4000)
Dead Ends
Common approaches that don't work:
-
尝试使用其他保留代码如1015
70% fail
所有1000-1015范围的代码都是协议保留
-
忽略错误继续发送消息
40% fail
连接已关闭,无法继续通信