Skip to content

Stream read and stream response "hangs", returns 327 bytes of 10 megabytes #11566

Answered by YuriiMotov
voltagex asked this question in Questions
Discussion options

You must be logged in to vote

When you do return await r in async_request, you return StreamRead object, but at the same time you close client session, that is used by that StreamRead object (when you call return you exit from context manager async with aiohttp.ClientSession() as client:)

So, you need to turn your async_request into async generator and iterate through r.content inside:

import logging
import sys

import aiohttp
from fastapi import FastAPI
from fastapi.responses import Response, StreamingResponse

logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)

app = FastAPI()

async def async_request():
    async with aiohttp.ClientSession() as client:
        logging.info("Start get")
        r = await cl…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@YuriiMotov
Comment options

Answer selected by voltagex
@voltagex
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem
2 participants