New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FastApi Error : "RuntimeError: Response content longer than Content-Length" #4949
Comments
Also , on trying the solution as told to follow in #4939, i am getting an error i have mentioned at bottom: ///Updated Code for delete request: @app.delete("/posts/{id}",status_code=status.HTTP_204_NO_CONTENT,response_class=Response)
///Getting below error: |
Hi Ben, |
I believe this is a duplicate of #4939. |
Thanks @sidraw-sys! It seems this was handled in #5145, available since FastAPI If that solves it, you could close the issue. Thanks! 🍰 Thanks for the help @florimondmanca! 🙇 |
Commenting on this ticket as well, since it's still open. This seems to be an issue for me still on fastapi 0.82.0. It can be reproduced like this: from fastapi import FastAPI, HTTPException
import uvicorn
app = FastAPI()
@app.get("/")
async def root():
raise HTTPException(204)
if __name__ == '__main__':
uvicorn.run(app, debug=True) Visiting the page results in:
|
Stuck with the same problem here |
@gazpachoking and @estronnom what version of Uvicorn are you using? |
@JarroVGIT 0.18.3 |
Yes, I can confirm this seems to be an issue. I checked with pure starlette, its working fine there. |
Same. 0.18.3 |
I think I got the issue, will make a PR. |
The reason this one keeps escaping the tests IMO is because FastAPI returns the given status code even if starlette raised 500 - Internal Server Error |
Assuming the original need was handled, this will be automatically closed now. But feel free to add more comments or create new issues or PRs. |
First Check
Commit to Help
Example Code
Description
I have started learning FastApi recently and have been following one youtube tutorial for lessons.
The issue i have been facing with this code is whenever I run delete_post request on Postman I get below error on uvicorn server:
"return Response(status_code=status.HTTP_204_NO_CONTENT)
TypeError: Response.init() got an unexpected keyword argument 'status_code'"
However, in the instructors video, this is working fine without any errors.
I searched and found few issues related to this on here which I tried to follow but couldn't get myself to resolve the error. I tried following few solutions as provided inside below ISSUE ID but to no avail-
" Response content longer than Content-Length error for DELETE and NoContent #4939"
The two prominent errors I am getting are:
"return Response(status_code=status.HTTP_204_NO_CONTENT)
TypeError: Response.init() got an unexpected keyword argument 'status_code'
***This is the original code which i am following from the youtube lesson
raise RuntimeError("Response content longer than Content-Length")
RuntimeError: Response content longer than Content-Length
***This is the error i am getting when I try to follow the solution provided in Issue id "4939".
Kindly assist, Thanks!
Operating System
Windows
Operating System Details
No response
FastAPI Version
0.78.0
Python Version
Python 3.10.4
Additional Context
NA
The text was updated successfully, but these errors were encountered: