Python 3.5: “async with” results in SyntaxError. Why? [duplicate]

时光怂恿深爱的人放手 提交于 2019-11-29 03:25:06

You can not use async with without async function. As the docs say:

It is a SyntaxError to use async with outside of an async def function.

But this code will work:

async def some_function():
    async with aiohttp.ClientSession() as session:
        pass

Or have a look at the example from the docs.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!