# RuntimeError: Invalid close code: 1006

- **ID:** `python/starlette-invalid-websocket-close-code`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

WebSocket关闭代码1006是协议保留值，不允许应用层使用

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.x | active | — | — |

## Workarounds

1. **使用合法的关闭代码（如1000正常关闭）** (95% success)
   ```
   await websocket.close(code=1000)
   ```
2. **使用自定义代码4000-4999范围** (90% success)
   ```
   await websocket.close(code=4000)
   ```

## Dead Ends

- **尝试使用其他保留代码如1015** — 所有1000-1015范围的代码都是协议保留 (70% fail)
- **忽略错误继续发送消息** — 连接已关闭，无法继续通信 (40% fail)
