python runtime_error ai_generated true

RuntimeError: 未返回响应。

RuntimeError: No response returned.

ID: python/starlette-no-response-returned

其他格式: JSON · Markdown 中文 · English
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.

generic

解决方案

  1. 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)
  2. 95% 成功率
    @app.get('/')\nasync def r():\n    return JSONResponse({})

无效尝试

常见但无效的做法:

  1. 90% 失败

    Swallowing exceptions leaves no response; error persists.

  2. 60% 失败

    Raises the original error but does not produce a Response.