Closed particle1331 closed 2 years ago
Hi @particle1331!
Yes, it's a (yet) unresolved issue in FastAPI. Here is the main issue tracking this: https://github.com/tiangolo/fastapi/issues/2832
The shortest solution is the following:
@app.delete("/posts/{id}", status_code=status.HTTP_204_NO_CONTENT, response_class=Response)
async def delete_post(id: int):
posts.pop(id, None)
return None
I made the choice to not mention it in the book because it'll (hopefully) be fixed at some point.
Note also that it happens when Uvicorn run the h11
HTTP implementation. When using the httptools
implementation, the error is ignored. If you installed Uvicorn with uvicorn[standard]
, httptools
should be used by default. You can try to force the implementation using the --http
flag:
uvicorn --http httptools chapter3_response_path_parameters_02:app
I'm getting the following error message when testing out chapter3_response_path_parameters_02.py.
This looks like a known issue. I'm guessing its because
content-length: 4
in the response when returningNone
. ReturningResponse(status_code=status.HTTP_204_NO_CONTENT)
seems to fix the issue (content-length zero in this case).