python runtime_error ai_generated true

RuntimeError: 未返回响应。

RuntimeError: No response returned.

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

其他格式: JSON · Markdown 中文 · English
80%修复率
84%置信度
0证据数
2024-09-15首次发现

版本兼容性

版本状态引入弃用备注
3.x active — — —

根因分析

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

English

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

generic

解决方案

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

无效尝试

常见但无效的做法:

  1. 75% 失败

    Hides the original exception and breaks streaming responses.

  2. 80% 失败

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