python runtime_error ai_generated true

RuntimeError: No response returned.

ID: python/starlette-no-response-returned

Also available as: JSON · Markdown · 中文
80%Fix Rate
85%Confidence
0Evidence
2024-04-03First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
0.30.x active — — —
0.36.x active — — —

Root Cause

A middleware or endpoint returned None instead of a Response, or an exception was swallowed without a response.

generic

中文

中间件或端点返回了None而不是Response,或者异常被吞掉且未返回响应。

Workarounds

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

Dead Ends

Common approaches that don't work:

  1. 90% fail

    Swallowing exceptions leaves no response; error persists.

  2. 60% fail

    Raises the original error but does not produce a Response.