我正在尝试从请求中获取查询和数据(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/