Python中使用aiohttp模拟服务器出现错误
软件版本及环境:Python 3.9 + pycharm 2020.2.1 + Windows10 运行报错: DeprecationWarning: loop argument is deprecatedapp = web.Application(loop=loop)DeprecationWarning: Application.make_handler(…) is deprecated, use AppRunner API insteadsrv = 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...
出错原因
新版本改动了库函数的使用
到此这篇关于Python中使用aiohttp模拟服务器出现错误的文章就介绍到这了,更多相关Python中使用aiohttp模拟服务器出现错误内容请搜索好吧啦网以前的文章或继续浏览下面的相关文章希望大家以后多多支持好吧啦网!
相关文章:
1. xml中的空格之完全解说2. HTML DOM setInterval和clearInterval方法案例详解3. asp中response.write("中文")或者js中文乱码问题4. html小技巧之td,div标签里内容不换行5. Warning: require(): open_basedir restriction in effect,目录配置open_basedir报错问题分析6. 完美实现CSS垂直居中的11种方法7. 阿里前端开发中的规范要求8. 前端从浏览器的渲染到性能优化9. html加css样式实现js美食项目首页示例代码10. CSS 使用Sprites技术实现圆角效果
