软件版本及环境:Python 3.9 + pycharm 2020.2.1 + Windows10 运行报错:

  • DeprecationWarning: loop argument is deprecated
  • app = web.Application(loop=loop)
  • DeprecationWarning: Application.make_handler(…) is deprecated, use AppRunner API instead
  • srv = await loop.create_server(app.make_handler(), ‘127.0.0.1', 8000)

出错代码

async def init(loop):
 app = web.Application(loop=loop)
 app.router.add_route('GET', '/', index)
 app.router.add_route('GET', '/hello/{name}', hello)
 srv = await loop.create_server(app.make_handler(), '127.0.0.1', 8000)
 print("Server started at http://127.0.0.1:8000...")
 return srv

解决方法 删除loop=loop

app = web.Application()

将app.make_handler()改为app()

srv = await loop.create_server(app(), '127.0.0.1', 8000)

运行结果

Server started at http://127.0.0.1:8000...

出错原因

新版本改动了库函数的使用

广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!