python
network_error
ai_generated
true
starlette.requests.ClientDisconnect: Client disconnected
ID: python/starlette-jsondecodeerror
80%Fix Rate
86%Confidence
0Evidence
2025-03-15First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 0.30.x | active | — | — | — |
| 0.40.x | active | — | — | — |
Root Cause
The client closed the connection before the server could read the full request body.
generic中文
客户端在服务器读取完整请求体之前关闭了连接。
Workarounds
-
90% success
try: await request.json() except ClientDisconnect: return JSONResponse(status_code=499, content={'detail': 'Client disconnected'}) -
85% success
async for chunk in request.stream(): if await request.is_disconnected(): break
Dead Ends
Common approaches that don't work:
-
80% fail
Client already disconnected; timeout doesn't help.
-
60% fail
May cause duplicate operations if not idempotent.