asyncio.run() cannot be called from a running event loop

运行如下程序时报错:
import aiohttp
import asyncio
async def main():
async with aiohttp.ClientSession() as session:
async with session.get('http://httpbin.org/get') as resp:
print(resp.status)
print(await resp.text())

asyncio.run(main)
报错提示:asyncio.run() cannot be called from a running event loop

asyncio.run(main)改为asyncio.run(main()),,代码如下:


import aiohttp
import asyncio
async def main():
    async with aiohttp.ClientSession() as session:
        async with session.get('http://httpbin.org/get') as resp:
            print(resp.status)
            print(await resp.text())

asyncio.run(main())

img