大佬教程收集整理的这篇文章主要介绍了RuntimeError:尝试使用 aiohttp 运行 https 请求时关闭了事件循环,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用 asyncio 和 aiohttp 来运行以下异步代码,但收到一个名为 RuntimeError: Event loop is closed 的奇怪错误。虽然我得到了理想的结果,但我没有得到这个错误背后的原因。我已经搜索了整个互联网,但找不到任何相关资源。我已经尝试过 here 提到的解决方案,但它对我不起作用。
`
import aiohttp
import asyncio
import time
start_time = time.time()
async def get_pokemon(session,url):
async with session.get(url) as resp:
pokemon = await resp.Json()
return pokemon['name']
async def main():
async with aiohttp.ClIEntSession() as session:
tasks = []
for number in range(1,15):
url = f'https://pokeAPI.co/API/v2/pokemon/{number}'
tasks.append(asyncio.ensure_future(get_pokemon(session,url)))
original_pokemon = await asyncio.gather(*tasks)
for pokemon in original_pokemon:
print(pokemon)
asyncio.run(main())
` 我的错误信息
RuntimeError: Event loop is closed
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x000000002BCCEB80>
TraceBACk (most recent call last):
file "C:\Python 38\lib\asyncio\proactor_events.py",line 116,in __del__
self.close()
file "C:\Python 38\lib\asyncio\proactor_events.py",line 108,in close
self._loop.call_soon(self._call_connection_lost,NonE)
file "C:\Python 38\lib\asyncio\base_events.py",line 719,in call_soon
self._check_closed()
file "C:\Python 38\lib\asyncio\base_events.py",line 508,in _check_closed
raise RuntimeError('Event loop is closed')
如果有人能帮我解决这个问题,那就太好了。 谢谢
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
以上是大佬教程为你收集整理的RuntimeError:尝试使用 aiohttp 运行 https 请求时关闭了事件循环全部内容,希望文章能够帮你解决RuntimeError:尝试使用 aiohttp 运行 https 请求时关闭了事件循环所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。