如何解决Python中aiohttp模拟服务器出现的错误问题?

2026-05-05 10:482阅读0评论SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计310个文字,预计阅读时间需要2分钟。

如何解决Python中aiohttp模拟服务器出现的错误问题?

软件版本及环境:Python 3.9 + PyCharm 2020.2.1 + Windows 10

运行报错:警告信息提示 DeprecationWarning: loop argument is deprecated 和 DeprecationWarning: Application.make_handler(...) is deprecated, use AppRunner

解决方法:

1.检查代码中是否有使用过时的 `loop` 参数。如果是,需要修改为 `loop=None`。

2.更新代码中的 `Application.make_handler` 方法,使用 `AppRunner` 替换。

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

出错代码

如何解决Python中aiohttp模拟服务器出现的错误问题?

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 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 127.0.0.1:8000...

出错原因

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

到此这篇关于Python中使用aiohttp模拟服务器出现错误的文章就介绍到这了,更多相关Python中使用aiohttp模拟服务器出现错误内容请搜索易盾网络以前的文章或继续浏览下面的相关文章希望大家以后多多支持易盾网络!

本文共计310个文字,预计阅读时间需要2分钟。

如何解决Python中aiohttp模拟服务器出现的错误问题?

软件版本及环境:Python 3.9 + PyCharm 2020.2.1 + Windows 10

运行报错:警告信息提示 DeprecationWarning: loop argument is deprecated 和 DeprecationWarning: Application.make_handler(...) is deprecated, use AppRunner

解决方法:

1.检查代码中是否有使用过时的 `loop` 参数。如果是,需要修改为 `loop=None`。

2.更新代码中的 `Application.make_handler` 方法,使用 `AppRunner` 替换。

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

出错代码

如何解决Python中aiohttp模拟服务器出现的错误问题?

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 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 127.0.0.1:8000...

出错原因

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

到此这篇关于Python中使用aiohttp模拟服务器出现错误的文章就介绍到这了,更多相关Python中使用aiohttp模拟服务器出现错误内容请搜索易盾网络以前的文章或继续浏览下面的相关文章希望大家以后多多支持易盾网络!