龙卷风requestHandler:如何在获得参数之前解码URL编码查询
我正在使用Python Tornado框架来构建API和请求Handler来处理我通过get()方法获得的查询。
我的处理程序
handlers = [
(r"?", MainHandler)
]
class MainHandler(RequestHandler):
def get(self):
args = {
"text": RequestHandler.get_argument(self, "text", default=""),
"lang": RequestHandler.get_argument(self, "lang", default=""),
}
# Process the query
......
问题是,当查询被编码时,例如“文本%3DHi%26lang%3DEN”,请求Handler不会解码查询并识别其两个参数。相反,它将“文本”参数值标识为“ hi& lang = en'。
那么,如果编码URL,我该如何阅读论点呢?显然requesthandler.get_arguments()似乎在解析URL参数之前似乎没有解码它们
I'm using the python Tornado framework to build an API and RequestHandler to handle the queries I get through the get() method.
My handler
handlers = [
(r"?", MainHandler)
]
class MainHandler(RequestHandler):
def get(self):
args = {
"text": RequestHandler.get_argument(self, "text", default=""),
"lang": RequestHandler.get_argument(self, "lang", default=""),
}
# Process the query
......
The issue is when the query is URL encoded like 'text%3DHi%26lang%3Den', the RequestHandler doesn't decode the query and identify its two parameters. Instead, it identifies the 'text' parameter value as 'Hi&lang=en'.
So, how do I read the arguments if they are URL encoded? Apparently RequestHandler.get_arguments() doesn't seem to be decoding them before parsing URL parameters
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于
&
字符也按照HTTP规格进行编码,因此将其视为值的一部分,而不是定界符。实际上,整个字符串 -
text%3DHi%26lang%3DEN
应该被视为一个值,因为分界符(=
和&
)也已编码。基本上,当您发送请求时,您只需要编码参数值,而不是整个查询。
Because the
&
character is also encoded, as per HTTP spec, it is treated as part of a the value, not as a delimiter.In fact, this whole string -
text%3DHi%26lang%3Den
should be considered a single value because the delimiters (=
and&
) are also encoded.Basically, when you're sending the request you only have to encode the argument values, not the whole querystring.