asyncio - AttributeError: '_WindowsSelectorEventLoop' object has no attribute 'create_future'

asyncio - AttributeError: '_WindowsSelectorEventLoop' object has no attribute 'create_future'

我正在尝试使用 Python 3(准确地说是 3.6.0a1)学习异步调用。

我已经访问了十几个不同的教程网站,加上 aiohttp 和 asyncio 文档,并保持 运行 进入相同的错误。我花了几个多小时在谷歌上搜索错误,并多次尝试在此处查找错误。

https://www.blog.pythonlibrary.org/2016/11/09/an-intro-to-aiohttp/ https://aiohttp.readthedocs.io/en/stable/client_quickstart.html#make-a-request https://medium.freecodecamp.org/a-guide-to-asynchronous-programming-in-python-with-asyncio-232e2afa44f6

这是代码,只是我从许多地方提取的示例:

import aiohttp
import asyncio


async def do_stuff():
    async with aiohttp.ClientSession() as session:
        async with session.get('https://api.github.com/events') as resp:
            print(resp.status)
            print(await resp.text())

loop = asyncio.get_event_loop()
loop.run_until_complete(do_stuff())
loop.close()

这里是错误:

文件“

<path>\Python\Python36\lib\site-packages\aiohttp\streams.py", line 531, in read
    self._waiter = self._loop.create_future()
AttributeError: '_WindowsSelectorEventLoop' object has no attribute 'create_future'

我一辈子都弄不明白自己做错了什么。我已经尝试了几十个教程示例,它们总是导致相同的 AttribteError。

有人能给我指出正确的方向吗?

Dim 提供了解决方案:我(在不知不觉中)使用了旧版本 Python 的 alpha 版本。

旧:3.6.0a1 新:3.6.4

世界上一切都很好。感谢您提供如此快速简单的解决方案。下次我会记住的!