python
runtime_error
ai_generated
true
RuntimeError: No response returned.
ID: python/starlette-runtime-error-no-response-returned
80%Fix Rate
88%Confidence
0Evidence
2024-08-22First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
An async view function does not return a valid response object.
generic中文
异步视图函数未返回有效的响应对象。
Workarounds
-
95% success Return a Response object
from starlette.responses import JSONResponse async def handle(request): return JSONResponse({'message': 'OK'}) -
90% success Use PlainTextResponse for simple text
from starlette.responses import PlainTextResponse async def handle(request): return PlainTextResponse('Hello')
Dead Ends
Common approaches that don't work:
-
Returning a string directly
80% fail
Starlette expects a Response object, not a string.
-
Forgetting return statement entirely
90% fail
Function returns None.