Python中使用aiohttp模拟服务器出现错误问题及解决方法_代码知识_七洗推广网

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

#代码知识 发布时间: 2026-01-12

软件版本及环境:Python 3.9 + pycharm 2025.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...

出错原因

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

代码知识SEO

上一篇 : react ant Design手动设置表单的值操作

下一篇 : JDBC查询Map转对象实现过程详解
品牌营销
专业SEO优化
添加左侧专家微信
获取产品详细报价方案