python
runtime_error
ai_generated
partial
RuntimeError: Unable to read request body, please use the stream parameter.
ID: python/starlette-request-body-stream-error
80%Fix Rate
80%Confidence
0Evidence
2024-08-14First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
尝试直接访问 request.body(),但请求体已经被消费。
generic中文
尝试直接访问 request.body(),但请求体已经被消费。
Workarounds
-
85% success
async def body_middleware(request, call_next): body = await request.body() request._body = body response = await call_next(request) return response
Dead Ends
Common approaches that don't work:
-
90% fail
请求体只能读取一次,第二次会抛出异常
-
60% fail
stream 需要正确管理,否则会导致内存泄漏