You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Windows10环境下使用asyncio与aiohttp出现RuntimeError: Event loop is closed错误的求助

RuntimeError: Event loop is closed with asyncio and aiohttp on Windows 10

Hey everyone,

I know this question might have been asked a hundred times already, but I still can't figure out why my code keeps throwing an error at the very end. I'm running this on Windows 10, and I'm totally new to asyncio—so I thought I was doing everything right, but clearly something's off. Could someone give me a gentle nudge in the right direction?

Here's my code:

import asyncio
import aiohttp

async def read_index_page():
    async with aiohttp.ClientSession() as session:
        async with session.get('https://some/api/url') as resp:
            print(resp.status)

async def main():
    loop = asyncio.get_event_loop()
    task = loop.create_task(read_index_page())
    await asyncio.gather(task)

if __name__ == '__main__':
    asyncio.run(main())

This code triggers the well-known RuntimeError: Event loop is closed error. I'm stuck here and would really appreciate any help.

Thanks,
Thomas

内容的提问来源于stack exchange,提问作者brillenheini

火山引擎 最新活动