# websockets.exceptions.InvalidStatusCode: server rejected WebSocket connection: HTTP 403

- **ID:** `python/starlette-websocket-handshake-403`
- **Domain:** python
- **Category:** auth_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

The WebSocket route raised before accept(), or an auth dependency returned a non-101 response, causing the handshake to be rejected.

## Version Compatibility

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

## Workarounds

1. **** (88% success)
   ```
   Accept first then validate: await websocket.accept(); if not token_ok: await websocket.close(code=1008)
   ```
2. **** (90% success)
   ```
   Pass token as query param: /ws?token=... and verify before accept
   ```

## Dead Ends

- **** — Server keeps rejecting; retries never succeed. (85% fail)
- **** — Security regression; not acceptable in production. (60% fail)
