我的加密网址如下:
我想在路线中使用解码的args:
@app.route('/interface/register', methods=['GET', 'POST'])
def interface_register():
args = request.args.to_dict()
id = args.get('id', "")
name = args.get('name', "")
...
所以我尝试在app.before_request中修改args:
@app.before_request
def before_request():
# decode and modify request.args
由于request.args是只读的,因此不成功,因此如何在调用request.args.to_dict()?
之前解码和修改原始request.args
答案 0 :(得分:0)
from urllib.parse import parse_qs, urlparse
def your_decode(qs):
# implement your decryption here
return qs
url = 'http://blah/?id=1&y=[1,2]&blah=dd' # >> replace with request.url
qs = urlparse(url).query
decoded_qs = your_decode(qs)
o = parse_qs(decoded_qs)
print(o)
打印
{'blah': ['dd'], 'id': ['1'], 'y': ['[1,2]']}