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.