修改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.sockets0.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已经被弃用了

如果程序运行正常,浏览器界面如下:

相关推荐
Lyn_Li几秒前
Kaggle Top 5 | 198只股票、200条数据的金融预测——BattleFin高分方案从零复现
python·kaggle·比赛复盘·金融预测
小九九的爸爸4 小时前
前端想要入门Agent开发,要具备哪些Python基础?
python·agent·ai编程
阿耶同学5 小时前
手把手教你用 LangGraph 搭建三层嵌套 Agent 架构
python·程序员
花酒锄作田1 天前
Pydantic校验配置文件
python
hboot1 天前
AI工程师第四课 - 深度学习入门
pytorch·python·神经网络
ZhengEnCi1 天前
P2M-Matplotlib折线图完全指南-从数据可视化到趋势分析的Python绘图利器
python·matlab·数据可视化
ZhengEnCi1 天前
P2L-Matplotlib饼图完全指南-从数据可视化到图表定制的Python绘图利器
python·matlab
曲幽1 天前
你的REST接口还在“过度投喂”数据吗?——FastAPI + GraphQL实战避坑指南
python·fastapi·web·graphql·route·cors·rest·strawberry
用户8358086187911 天前
基于 Self-RAG 与列表级重排序的进阶 RAG 系统设计与实现
python
Warson_L2 天前
Python `Annotated` 与 LangGraph Reducer 学习笔记
python