python
auth_error
ai_generated
true
websockets.exceptions.InvalidStatusCode: server rejected WebSocket connection: HTTP 403
ID: python/starlette-websocket-handshake-403
80%Fix Rate
84%Confidence
0Evidence
2024-10-21First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
The WebSocket route raised before accept(), or an auth dependency returned a non-101 response, causing the handshake to be rejected.
generic中文
WebSocket 路由在 accept() 之前抛出异常,或认证依赖返回了非 101 响应,导致握手被拒绝。
Workarounds
-
88% success
Accept first then validate: await websocket.accept(); if not token_ok: await websocket.close(code=1008)
-
90% success
Pass token as query param: /ws?token=... and verify before accept
Dead Ends
Common approaches that don't work:
-
85% fail
Server keeps rejecting; retries never succeed.
-
60% fail
Security regression; not acceptable in production.