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

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

相关推荐
zhaoyong22239 分钟前
MySQL 存储过程中字符集与排序规则不匹配导致查询性能下降的解决方案
jvm·数据库·python
sinat_3834373640 分钟前
golang如何从Python转型Go开发_golang从Python转型Go开发攻略
jvm·数据库·python
rockey6271 小时前
基于AScript的python3脚本语言发布啦!
python·c#·.net·script·python3·eval·expression·function·动态脚本
gqk011 小时前
Python入门
python
Muyuan19982 小时前
28.Paper RAG Agent 开发记录:修复 LLM Rerank 的解析、Fallback 与可验证性
linux·人工智能·windows·python·django·fastapi
代码小书生2 小时前
statistics,一个统计的 Python 库!
开发语言·python
STLearner2 小时前
SIGIR 2026 | LLM × Graph论文总结(图增强LLM,GraphRAG,Agent,多模态,知识图谱,搜索,推
人工智能·python·深度学习·神经网络·机器学习·数据挖掘·知识图谱
FreakStudio2 小时前
MicroPython 内核开发者直接狂喜!这个 Claude 插件市场,把开发全流程做成了「对话式外挂」
python·单片机·嵌入式·面向对象·并行计算·电子diy
老陈说编程3 小时前
12. LangChain 6大核心调用方法:invoke/stream/batch同步异步全解析,新手也能轻松学会
开发语言·人工智能·python·深度学习·机器学习·ai·langchain
给自己做减法3 小时前
rag混合检索
人工智能·python·rag