我尝试使用python3(确切地说是3.6.0a1)学习异步调用。在
我访问了十几个不同的教程网站,加上aiohttp和asyncio文档,一直遇到同样的错误。我已经花了几个小时在google上搜索了这个错误,还尝试了几个小时来查找这个错误。在
https://www.blog.pythonlibrary.org/2016/11/09/an-intro-to-aiohttp/https://aiohttp.readthedocs.io/en/stable/client_quickstart.html#make-a-requesthttps://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()
错误如下:
“文件”
^{pr2}$我一辈子都搞不清自己做错了什么。我已经尝试了几十个教程的例子,它们总是导致相同的AttribteError。在
有人能给我指一下正确的方向吗?在
Dim提供了解决方案:我正在(不知不觉中)使用Python旧版本的alpha版本。在
旧版:3.6.0a1 新增:3.6.4
世界上一切都很好。谢谢你这么快和简单的解决办法。下次我会记住的!在
相关问题 更多 >
编程相关推荐