Starlette is not handling some invalid json format on Request.json() #2874
-
This comes from an investigation i was doing on a Fastapi issue fastapi/fastapi#13388, but the root cause should be in starlette. Starlette starlette/starlette/requests.py Lines 246 to 250 in 1695942 While JSONResponse.render() is stricly enforcing JSON specification.starlette/starlette/responses.py Lines 183 to 190 in 1695942 MRESending as json body:
Will start to raise exception from import uvicorn
from starlette.applications import Starlette, Request
from starlette.responses import JSONResponse
from starlette.routing import Route
async def homepage(request: Request):
body = await request.json()
return JSONResponse(body)
routes = [
Route("/items", endpoint=homepage, methods=["POST"])
]
app = Starlette(debug=True, routes=routes)
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Seems duplicated: #1518 |
Beta Was this translation helpful? Give feedback.
Seems duplicated: #1518