raise RemoteProtocolError( h11._util.RemoteProtocolError: Receive buffer too long

Viewed 78

I have written code for fastapi and my API takes input base64 gif string and I'm getting this error basically the problem is when I have passed a big string then I'm getting this error but when I have passed the small or average size string then API runs successfully and give me a response. Anybody knows how to fix this error.

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import FileResponse
import base64
app = FastAPI()
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials= True,
    allow_methods=["*"],
    allow_headers=["*"],
)

@app.get("/myapp",response_class=FileResponse)
async def detection(gif_url: str,img_url: str):
    
    gif_data = base64.b64decode(gif_url)
    gif_data_file = open("source.gif", "wb")
    gif_data_file.write(gif_data)
    
    return {"message":"Gif saved"}
    

gif_url receive base64 gif string.

1 Answers

This is actually caused by h11 that is used by Uvicorn. I am assuming you are running this using Uvicorn. Recently, an option was added to it, that will help you with this:

* `--h11-max-incomplete-event-size <int>` - Set the maximum number of bytes to buffer of an incomplete event. Only available for `h11` HTTP protocol implementation. **Default:** *'16384'* (16 KB).

Try raising this to fit your needs.

Related