Skip to content

Async generator returns an error and generator inconsistencies #1842

@sidux

Description

@sidux

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions