<h3 dir="auto">First Check</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I added a very descriptive title to this issue.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I used the GitHub search to find a similar issue and didn't find it.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I searched the FastAPI documentation, with the integrated search.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I already searched in Google "How to X in FastAPI" and didn't find any information.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I already read and followed all the tutorial in the docs and didn't find an answer.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I already checked if it is not related to FastAPI but to <a href="https://github.com/samuelcolvin/pydantic">Pydantic</a>.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I already checked if it is not related to FastAPI but to <a href="https://github.com/swagger-api/swagger-ui">Swagger UI</a>.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I already checked if it is not related to FastAPI but to <a href="https://github.com/Redocly/redoc">ReDoc</a>.</li>
</ul>
<h3 dir="auto">Commit to Help</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I commit to help with one of those options 👆</li>
</ul>
<h3 dir="auto">Example Code</h3>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="#dummy list for posts
my_posts=[{&quot;title&quot;:&quot;Post 1&quot;,&quot;content&quot;:&quot;Content of Post 1&quot;,&quot;id&quot;:1 },
          {&quot;title&quot;:&quot;Post 2&quot;,&quot;content&quot;:&quot;Content of Post 2&quot;,&quot;id&quot;:2 },
          {&quot;title&quot;:&quot;Post 3&quot;,&quot;content&quot;:&quot;Content of Post 3&quot;,&quot;id&quot;:3 }  
         ]

#function to get the index of the post which I am looking to delete by matching the ID
def find_index_post(id):
    for i, p in enumerate(my_posts):
        if p['id']==id:
            return i

#delete request created using FastApi
@app.delete(&quot;/posts/{id}&quot;,status_code=status.HTTP_204_NO_CONTENT)
def delete_post(id:int):
    index=find_index_post(id)
    if index==None:
        raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f&quot;Post with Id {id} does not 
        exist!&quot;)
    
    my_posts.pop(index)
    return Response(status_code=status.HTTP_404_NOT_FOUND)"><pre class="notranslate"><span class="pl-c">#dummy list for posts</span>
<span class="pl-s1">my_posts</span><span class="pl-c1">=</span>[{<span class="pl-s">"title"</span>:<span class="pl-s">"Post 1"</span>,<span class="pl-s">"content"</span>:<span class="pl-s">"Content of Post 1"</span>,<span class="pl-s">"id"</span>:<span class="pl-c1">1</span> },
          {<span class="pl-s">"title"</span>:<span class="pl-s">"Post 2"</span>,<span class="pl-s">"content"</span>:<span class="pl-s">"Content of Post 2"</span>,<span class="pl-s">"id"</span>:<span class="pl-c1">2</span> },
          {<span class="pl-s">"title"</span>:<span class="pl-s">"Post 3"</span>,<span class="pl-s">"content"</span>:<span class="pl-s">"Content of Post 3"</span>,<span class="pl-s">"id"</span>:<span class="pl-c1">3</span> }  
         ]

<span class="pl-c">#function to get the index of the post which I am looking to delete by matching the ID</span>
<span class="pl-k">def</span> <span class="pl-en">find_index_post</span>(<span class="pl-s1">id</span>):
    <span class="pl-k">for</span> <span class="pl-s1">i</span>, <span class="pl-s1">p</span> <span class="pl-c1">in</span> <span class="pl-en">enumerate</span>(<span class="pl-s1">my_posts</span>):
        <span class="pl-k">if</span> <span class="pl-s1">p</span>[<span class="pl-s">'id'</span>]<span class="pl-c1">==</span><span class="pl-s1">id</span>:
            <span class="pl-k">return</span> <span class="pl-s1">i</span>

<span class="pl-c">#delete request created using FastApi</span>
<span class="pl-en">@<span class="pl-s1">app</span>.<span class="pl-en">delete</span>(<span class="pl-s">"/posts/{id}"</span>,<span class="pl-s1">status_code</span><span class="pl-c1">=</span><span class="pl-s1">status</span>.<span class="pl-v">HTTP_204_NO_CONTENT</span>)</span>
<span class="pl-k">def</span> <span class="pl-en">delete_post</span>(<span class="pl-s1">id</span>:<span class="pl-s1">int</span>):
    <span class="pl-s1">index</span><span class="pl-c1">=</span><span class="pl-en">find_index_post</span>(<span class="pl-s1">id</span>)
    <span class="pl-k">if</span> <span class="pl-s1">index</span><span class="pl-c1">==</span><span class="pl-c1">None</span>:
        <span class="pl-k">raise</span> <span class="pl-v">HTTPException</span>(<span class="pl-s1">status_code</span><span class="pl-c1">=</span><span class="pl-s1">status</span>.<span class="pl-v">HTTP_404_NOT_FOUND</span>, <span class="pl-s1">detail</span><span class="pl-c1">=</span>f"Post with Id <span class="pl-s1"><span class="pl-kos">{</span><span class="pl-s1">id</span><span class="pl-kos">}</span></span> <span class="pl-s1">does</span> <span class="pl-c1">not</span> 
        <span class="pl-s1">exist</span>!<span class="pl-s">"</span>)
    
    <span class="pl-s1">my_posts</span>.<span class="pl-en">pop</span>(<span class="pl-s1">index</span>)
    <span class="pl-k">return</span> <span class="pl-v">Response</span>(<span class="pl-s1">status_code</span><span class="pl-c1">=</span><span class="pl-s1">status</span>.<span class="pl-v">HTTP_404_NOT_FOUND</span>)</pre></div>
<h3 dir="auto">Description</h3>
<p dir="auto">I have started learning FastApi recently and have been following one youtube tutorial for lessons.</p>
<p dir="auto">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:<br>
"return Response(status_code=status.HTTP_204_NO_CONTENT)<br>
TypeError: Response.<strong>init</strong>() got an unexpected keyword argument 'status_code'"<br>
However, in the instructors video, this is working fine without any errors.</p>
<p dir="auto">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-<br>
" Response content longer than Content-Length error for DELETE and NoContent <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1244915501" data-permission-text="Title is private" data-url="https://github.com/tiangolo/fastapi/issues/4939" data-hovercard-type="issue" data-hovercard-url="/tiangolo/fastapi/issues/4939/hovercard" href="https://github.com/tiangolo/fastapi/issues/4939">#4939</a>"</p>
<p dir="auto">The two prominent errors I am getting are:</p>
<ul dir="auto">
<li>
<p dir="auto">"return Response(status_code=status.HTTP_204_NO_CONTENT)<br>
TypeError: Response.<strong>init</strong>() got an unexpected keyword argument 'status_code'<br>
***This is the original code which i am following from the youtube lesson</p>
</li>
<li>
<p dir="auto">raise RuntimeError("Response content longer than Content-Length")<br>
RuntimeError: Response content longer than Content-Length<br>
***This is the error i am getting when I try to follow the solution provided in Issue id "4939".</p>
</li>
</ul>
<p dir="auto">Kindly assist, Thanks!</p>
<h3 dir="auto">Operating System</h3>
<p dir="auto">Windows</p>
<h3 dir="auto">Operating System Details</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">FastAPI Version</h3>
<p dir="auto">0.78.0</p>
<h3 dir="auto">Python Version</h3>
<p dir="auto">Python 3.10.4</p>
<h3 dir="auto">Additional Context</h3>
<p dir="auto">NA</p>
<h3 dir="auto">First Check</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I added a very descriptive title to this issue.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I used the GitHub search to find a similar issue and didn't find it.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I searched the FastAPI documentation, with the integrated search.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I already searched in Google "How to X in FastAPI" and didn't find any information.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I already read and followed all the tutorial in the docs and didn't find an answer.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I already checked if it is not related to FastAPI but to <a href="https://github.com/samuelcolvin/pydantic">Pydantic</a>.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I already checked if it is not related to FastAPI but to <a href="https://github.com/swagger-api/swagger-ui">Swagger UI</a>.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I already checked if it is not related to FastAPI but to <a href="https://github.com/Redocly/redoc">ReDoc</a>.</li>
</ul>
<h3 dir="auto">Commit to Help</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I commit to help with one of those options <g-emoji class="g-emoji" alias="point_up_2" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f446.png">👆</g-emoji></li>
</ul>
<h3 dir="auto">Example Code</h3>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from fastapi import FastAPI, status

app = FastAPI()


@app.delete(&quot;/&quot;, status_code=status.HTTP_204_NO_CONTENT)
def read_root():
    return None"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">fastapi</span> <span class="pl-k">import</span> <span class="pl-v">FastAPI</span>, <span class="pl-s1">status</span>

<span class="pl-s1">app</span> <span class="pl-c1">=</span> <span class="pl-v">FastAPI</span>()


<span class="pl-en">@<span class="pl-s1">app</span>.<span class="pl-en">delete</span>(<span class="pl-s">"/"</span>, <span class="pl-s1">status_code</span><span class="pl-c1">=</span><span class="pl-s1">status</span>.<span class="pl-v">HTTP_204_NO_CONTENT</span>)</span>
<span class="pl-k">def</span> <span class="pl-en">read_root</span>():
    <span class="pl-k">return</span> <span class="pl-c1">None</span></pre></div>
<h3 dir="auto">Description</h3>
<p dir="auto">Upon requesting above code I got expected response but my logs shows that there is an error in uvicorn. The problem exists for DELETE method and NoContent response status code (for HEAD there is no such problem)</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File &quot;/home/user/PycharmProjects/sample_app/venv/lib/python3.9/site-packages/uvicorn/protocols/http/httptools_impl.py&quot;, line 372, in run_asgi
    result = await app(self.scope, self.receive, self.send)
  File &quot;/home/user/PycharmProjects/sample_app/venv/lib/python3.9/site-packages/uvicorn/middleware/proxy_headers.py&quot;, line 75, in __call__
    return await self.app(scope, receive, send)
  File &quot;/home/user/PycharmProjects/sample_app/venv/lib/python3.9/site-packages/fastapi/applications.py&quot;, line 269, in __call__
    await super().__call__(scope, receive, send)
  File &quot;/home/user/PycharmProjects/sample_app/venv/lib/python3.9/site-packages/starlette/applications.py&quot;, line 124, in __call__
    await self.middleware_stack(scope, receive, send)
  File &quot;/home/user/PycharmProjects/sample_app/venv/lib/python3.9/site-packages/starlette/middleware/errors.py&quot;, line 184, in __call__
    raise exc
  File &quot;/home/user/PycharmProjects/sample_app/venv/lib/python3.9/site-packages/starlette/middleware/errors.py&quot;, line 162, in __call__
    await self.app(scope, receive, _send)
  File &quot;/home/user/PycharmProjects/sample_app/venv/lib/python3.9/site-packages/starlette/exceptions.py&quot;, line 93, in __call__
    raise exc
  File &quot;/home/user/PycharmProjects/sample_app/venv/lib/python3.9/site-packages/starlette/exceptions.py&quot;, line 82, in __call__
    await self.app(scope, receive, sender)
  File &quot;/home/user/PycharmProjects/sample_app/venv/lib/python3.9/site-packages/fastapi/middleware/asyncexitstack.py&quot;, line 21, in __call__
    raise e
  File &quot;/home/user/PycharmProjects/sample_app/venv/lib/python3.9/site-packages/fastapi/middleware/asyncexitstack.py&quot;, line 18, in __call__
    await self.app(scope, receive, send)
  File &quot;/home/user/PycharmProjects/sample_app/venv/lib/python3.9/site-packages/starlette/routing.py&quot;, line 670, in __call__
    await route.handle(scope, receive, send)
  File &quot;/home/user/PycharmProjects/sample_app/venv/lib/python3.9/site-packages/starlette/routing.py&quot;, line 266, in handle
    await self.app(scope, receive, send)
  File &quot;/home/user/PycharmProjects/sample_app/venv/lib/python3.9/site-packages/starlette/routing.py&quot;, line 68, in app
    await response(scope, receive, send)
  File &quot;/home/user/PycharmProjects/sample_app/venv/lib/python3.9/site-packages/starlette/responses.py&quot;, line 162, in __call__
    await send({&quot;type&quot;: &quot;http.response.body&quot;, &quot;body&quot;: self.body})
  File &quot;/home/user/PycharmProjects/sample_app/venv/lib/python3.9/site-packages/starlette/exceptions.py&quot;, line 79, in sender
    await send(message)
  File &quot;/home/user/PycharmProjects/sample_app/venv/lib/python3.9/site-packages/starlette/middleware/errors.py&quot;, line 159, in _send
    await send(message)
  File &quot;/home/user/PycharmProjects/sample_app/venv/lib/python3.9/site-packages/uvicorn/protocols/http/httptools_impl.py&quot;, line 501, in send
    raise RuntimeError(&quot;Response content longer than Content-Length&quot;)
RuntimeError: Response content longer than Content-Length```

### Operating System

Linux

### Operating System Details

_No response_

### FastAPI Version

0.78.0

### Python Version

3.10

### Additional Context

_No response_"><pre lang="INFO:" class="notranslate"><code class="notranslate">ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/home/user/PycharmProjects/sample_app/venv/lib/python3.9/site-packages/uvicorn/protocols/http/httptools_impl.py", line 372, in run_asgi
    result = await app(self.scope, self.receive, self.send)
  File "/home/user/PycharmProjects/sample_app/venv/lib/python3.9/site-packages/uvicorn/middleware/proxy_headers.py", line 75, in __call__
    return await self.app(scope, receive, send)
  File "/home/user/PycharmProjects/sample_app/venv/lib/python3.9/site-packages/fastapi/applications.py", line 269, in __call__
    await super().__call__(scope, receive, send)
  File "/home/user/PycharmProjects/sample_app/venv/lib/python3.9/site-packages/starlette/applications.py", line 124, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/user/PycharmProjects/sample_app/venv/lib/python3.9/site-packages/starlette/middleware/errors.py", line 184, in __call__
    raise exc
  File "/home/user/PycharmProjects/sample_app/venv/lib/python3.9/site-packages/starlette/middleware/errors.py", line 162, in __call__
    await self.app(scope, receive, _send)
  File "/home/user/PycharmProjects/sample_app/venv/lib/python3.9/site-packages/starlette/exceptions.py", line 93, in __call__
    raise exc
  File "/home/user/PycharmProjects/sample_app/venv/lib/python3.9/site-packages/starlette/exceptions.py", line 82, in __call__
    await self.app(scope, receive, sender)
  File "/home/user/PycharmProjects/sample_app/venv/lib/python3.9/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in __call__
    raise e
  File "/home/user/PycharmProjects/sample_app/venv/lib/python3.9/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
    await self.app(scope, receive, send)
  File "/home/user/PycharmProjects/sample_app/venv/lib/python3.9/site-packages/starlette/routing.py", line 670, in __call__
    await route.handle(scope, receive, send)
  File "/home/user/PycharmProjects/sample_app/venv/lib/python3.9/site-packages/starlette/routing.py", line 266, in handle
    await self.app(scope, receive, send)
  File "/home/user/PycharmProjects/sample_app/venv/lib/python3.9/site-packages/starlette/routing.py", line 68, in app
    await response(scope, receive, send)
  File "/home/user/PycharmProjects/sample_app/venv/lib/python3.9/site-packages/starlette/responses.py", line 162, in __call__
    await send({"type": "http.response.body", "body": self.body})
  File "/home/user/PycharmProjects/sample_app/venv/lib/python3.9/site-packages/starlette/exceptions.py", line 79, in sender
    await send(message)
  File "/home/user/PycharmProjects/sample_app/venv/lib/python3.9/site-packages/starlette/middleware/errors.py", line 159, in _send
    await send(message)
  File "/home/user/PycharmProjects/sample_app/venv/lib/python3.9/site-packages/uvicorn/protocols/http/httptools_impl.py", line 501, in send
    raise RuntimeError("Response content longer than Content-Length")
RuntimeError: Response content longer than Content-Length```

### Operating System

Linux

### Operating System Details

_No response_

### FastAPI Version

0.78.0

### Python Version

3.10

### Additional Context

_No response_
</code></pre></div>