当前位置:主页 > 软件编程 > Python代码 >

Python中使用aiohttp模拟服务器出现错误问题及解决方法

时间:2021-07-10 09:32:36 | 栏目:Python代码 | 点击:

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

出错代码

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...

出错原因

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

您可能感兴趣的文章:

相关文章