Python中使用aiohttp模擬服務(wù)器出現(xiàn)錯誤
軟件版本及環(huán)境: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)
運行結(jié)果
Server started at http://127.0.0.1:8000...
出錯原因
新版本改動了庫函數(shù)的使用
到此這篇關(guān)于Python中使用aiohttp模擬服務(wù)器出現(xiàn)錯誤的文章就介紹到這了,更多相關(guān)Python中使用aiohttp模擬服務(wù)器出現(xiàn)錯誤內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
