Python中aiohttp模拟服务器报错:DeprecationWarning: loop argument is deprecated【已解决】

今天爱分享给大家带来Python中aiohttp模拟服务器报错:DeprecationWarning: loop argument is deprecated【已解决】,希望能够帮助到大家。

软件版本及环境: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

解决方法
1.删除loop=loop

app = web.Application()

2.将app.make_handler()改为app()

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

运行结果

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

出错原因
新版本改动了库函数的使用

原文链接:https://blog.itblood.com/937.html,转载请注明出处。
0
受孕吧!爆乳天国天使宝贝2~王都攻略篇~挂载AI汉化版+存档[新作][2.4G] [RPG/汉化/动态/CV]
受孕吧!爆乳天国天使宝贝2~王都攻略篇~挂载AI汉化版+存档[新作][2.4G] [RPG/汉化/动态/CV]
9分钟前 有人购买 去瞅瞅看

站点公告

显示验证码
没有账号?注册  忘记密码?