python
runtime_error
ai_generated
true
RuntimeError: 未返回响应。
RuntimeError: No response returned.
ID: python/starlette-no-response-returned
80%修复率
85%置信度
0证据数
2024-04-03首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 0.30.x | active | — | — | — |
| 0.36.x | active | — | — | — |
根因分析
中间件或端点返回了None而不是Response,或者异常被吞掉且未返回响应。
English
A middleware or endpoint returned None instead of a Response, or an exception was swallowed without a response.
解决方案
-
92% 成功率
async def mw(request, call_next):\n try:\n return await call_next(request)\n except Exception:\n return JSONResponse({'err': 'x'}, status_code=500) -
95% 成功率
@app.get('/')\nasync def r():\n return JSONResponse({})
无效尝试
常见但无效的做法:
-
90% 失败
Swallowing exceptions leaves no response; error persists.
-
60% 失败
Raises the original error but does not produce a Response.