You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have created a lambda API using Cloudformation. When I chat with a file attachment included, I get the following error.
_File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 161, in send
await send(message)
File "/usr/local/lib/python3.11/site-packages/uvicorn/protocols/http/httptools_impl.py", line 528, in send
raise RuntimeError("Response content longer than Content-Length")
RuntimeError: Response content longer than Content-Length
Chats without attachment seems to be fine.
After some search I found this:
Best Practices for Setting Content-Length in FastAPI
Leverage Automatic Handling by FastAPI:
FastAPI automatically includes the Content-Length header for most responses, based on the response content size. This applies when using built-in response classes like JSONResponse, HTMLResponse, or custom responses with the Response class1.
Avoid manually setting the Content-Length unless absolutely necessary.
Use Appropriate Response Classes:
Use built-in response classes such as HTMLResponse, JSONResponse, or FileResponse to ensure that headers, including Content-Length, are handled correctly.
from fastapi import FastAPI
from fastapi.responses import HTMLResponse
app = FastAPI()
@app.get("/", response_class=HTMLResponse)
async def read_items():
return "<html><body>Hello, World!</body></html>"
There is no such error when I call other API based AI services. So, it seems something needs to be fixed.
The text was updated successfully, but these errors were encountered:
Hi,
I have created a lambda API using Cloudformation. When I chat with a file attachment included, I get the following error.
_File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 161, in send
await send(message)
File "/usr/local/lib/python3.11/site-packages/uvicorn/protocols/http/httptools_impl.py", line 528, in send
raise RuntimeError("Response content longer than Content-Length")
RuntimeError: Response content longer than Content-Length
Chats without attachment seems to be fine.
After some search I found this:
Best Practices for Setting Content-Length in FastAPI
Leverage Automatic Handling by FastAPI:
FastAPI automatically includes the Content-Length header for most responses, based on the response content size. This applies when using built-in response classes like JSONResponse, HTMLResponse, or custom responses with the Response class1.
Avoid manually setting the Content-Length unless absolutely necessary.
Use Appropriate Response Classes:
Use built-in response classes such as HTMLResponse, JSONResponse, or FileResponse to ensure that headers, including Content-Length, are handled correctly.
There is no such error when I call other API based AI services. So, it seems something needs to be fixed.
The text was updated successfully, but these errors were encountered: