本文主要是介绍修改http_charfinder.py使能在python311环境中运行,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
需要修改两个函数,第一个是init函数,修改如下:
async def init(loop, address, port): # <1>
# app = web.Application(loop=loop) # <2>
# app.router.add_route('GET', '/', home) # <3>
app = web.Application() # <2>
app.add_routes([web.get('/', home)])
# handler = app.make_handler() # <4>
# server = yield from loop.create_server(handler,
# address, port) # <5>
runner = web.AppRunner(app)
await runner.setup()
server = await loop.create_server(runner.server,
address, port) # <5>
return server.sockets[0].getsockname() # <6>
不修改程序会报deprecation警报
第二个函数是home函数,修改如下:
def home(request): # <1>
# query = request.GET.get('query', '').strip() # <2>
query = request.query.get('query', '').strip() # <2>
...
不修改程序会报如下错误:
Error handling request
Traceback (most recent call last):
...
File "D:\fluentPy\chapter17_18\http_charfinder.py", line 29, in home
query = request.GET.get('query', '').strip() # <2>
^^^^^^^^^^^
AttributeError: 'Request' object has no attribute 'GET'
因为request.GET已经被弃用了
如果程序运行正常,浏览器界面如下:
这篇关于修改http_charfinder.py使能在python311环境中运行的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!