您的位置:首頁技術文章
文章詳情頁

Python中使用aiohttp模擬服務器出現錯誤

瀏覽:4日期:2022-07-06 16:33:42

軟件版本及環境: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模擬服務器出現錯誤內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Python 編程
相關文章:
国产综合久久一区二区三区