繁体   English   中英

如何在python中通过reqparse.parser读取多个url编码的文本

[英]How to read multi url-encoded text by reqparse.parser in python

我正在使用 python (flask) 使用以下代码从命令行读取输入,但是当我传递 url 编码的字符串(用空格分隔的多个参数)作为输入时,它会合并为单个字符串,空格为“+”。

示例.py

from flask_restful import reqparse
parser = reqparse.RequestParser()
parser.add_argument('output')
args = parser.parse_args()
indata=args['output']
print(urllib.parse.quote_plus(indata))

跑:

python sample.py 
curl http://localhost:5000/mypage -d "output=ld%22+to+the+term old+%7B%0A++++pub" -X POST -v

输出:

 ld%22+to+the+term+old+%7B%0A++++pubin

虽然我希望输出是

   ld%22+to+the+term  old+%7B%0A++++pubin  (so that they can be spitted easily with separator)

我怎样才能避免这样的事情?

您不能在表单参数中使用空格(在 curl 中使用-d传递)。

我建议您在将参数传递给 curl 之前对参数进行 urlencode,或者使用其他一些为您执行此操作的 http 客户端。 例如请求httpie

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM