Pythoncherpy,解析query_string

标签 python parsing cherrypy

我正在尝试从请求中获取查询和数据(GET 参数和 POST 参数)

curl --data "foo=bar&hello=world" "http://localhost:8080/mypath?orange=5&apple=8"

.

query_string = cherrypy.request.query_string  # 'orange=5&apple=8'
post_data = cherrypy.request.body.params  # {'foo': 'bar', 'hello': 'world'}

post_data 是正确的字典形式。 我怎样才能像post_data一样解析query_string?

我在cherrypy doc上阅读,我看到了这个:

process_query_string()

Parse the query string into Python structures. (Core)

但这不起作用,cherrypy.request.process_query_string() a is returns None

有什么想法吗?

最佳答案

CherryPy 使用 cherrypy.lib.httputil.parse_query_string 来使用 GET 参数填充 request.params,您可以像这样使用它:

from cherrypy.lib.httputil import parse_query_string
parse_query_string(cherrypy.request.query_string)

它返回带有解析的查询字符串参数的字典。

关于Pythoncherpy,解析query_string,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18683558/

相关文章:

parsing - 安特尔 4 : Method for switching modes in parser

python - CherryPy Ping 数据库连接或重启连接

python - Cherrypy 中的内存消耗

python - 检查应用程序是否在服务器或本地运行

python - 如何检查特定数字是否为整数

c# - 检测脚本中未声明的变量

python - 如何确保应用程序窗口始终在最前面?

python - 将 boolean 公式映射到 Python 集合表达式

python - 在Python中将一系列颜色更改为白色

python - 在 Python 中获得响应后模拟 requests.json