AttributeError: module 'asyncio' has no attribute 'run'

python_logo.png

asyncio.run是python 3.7的新增加的。在3.5-3.6中,就会报这个错误。

可以修改为:loop.run_until_complete

示例:

async def call_url(url):   
  print('Starting {}'.format(url))  

# ----------------------------------
loop = asyncio.new_event_loop()      
contr = call_url("http://baidu.com")
task = loop.create_task(contr)
loop.run_until_complete(task)
loop.close()
Last modification:April 28th, 2020 at 04:04 pm
If you think my article is useful to you, please feel free to appreciate