Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async generator returns an error and generator inconsistencies #1842

Open
sidux opened this issue Dec 28, 2023 · 0 comments · May be fixed by #1844
Open

Async generator returns an error and generator inconsistencies #1842

sidux opened this issue Dec 28, 2023 · 0 comments · May be fixed by #1844

Comments

@sidux
Copy link

sidux commented Dec 28, 2023

When using AsyncApp and a route returns an async generator I get the error : AttributeError: 'coroutine' object has no attribute 'encode'

for example :

async def route():
    async def gen():
        while True:
            yield json.dumps({'msg': 'Hello World!'}) + '\n\n'
            await asyncio.sleep(0.5)

    return StreamingResponse(gen())

When the generator is not async everything works fine.

When the generator is not async and using AsyncApp StreamingResponse is needed
but when using FlaskApp returning the generator directly works fine.

@sidux sidux linked a pull request Dec 29, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant