python runtime_error ai_generated true

RuntimeError: No response returned.

ID: python/starlette-runtimeerror-no-response-returned

Also available as: JSON · Markdown · 中文
80%Fix Rate
84%Confidence
0Evidence
2024-09-15First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active — — —

Root Cause

An ASGI middleware or endpoint returns None instead of a Response, or an exception is swallowed inside a BaseHTTPMiddleware dispatch.

generic

中文

ASGI 中间件或端点返回 None 而非 Response,或异常在 BaseHTTPMiddleware 的 dispatch 中被吞掉。

Workarounds

  1. 93% success
    class M(BaseHTTPMiddleware):
        async def dispatch(self, request, call_next):
            response = await call_next(request)
            return response
  2. 90% success
    try:
        response = await call_next(request)
    except Exception:
        raise

Dead Ends

Common approaches that don't work:

  1. 75% fail

    Hides the original exception and breaks streaming responses.

  2. 80% fail

    Behavior persists across versions; root cause is the middleware logic.