FastAPI's StreamingResponse doesn't return stream

1.1k Views Asked by At

Trying FastAPI's StreamingResponse, however getting TypeError: stream.on is not a function in the browser:

    const response = await axios.get("http://localhost:8000/stream", {
      responseType: "stream",
    });

    const stream = response.data;

    stream.on("data", (data) => {
      console.log(event.data);
    });

Server endpoint (code snippet):

    def get_stream():
        yield 'a'
        yield 'b'
        yield 'c'


    @app.get("/stream")
    async def main():
        return StreamingResponse(get_stream(), media_type="text/plain")

I also tried passing --h11-max-incomplete-event-size 0 argument to uvicorn command as mentioned here: https://www.uvicorn.org/settings/

0

There are 0 best solutions below