url decode
Posted: Sun Feb 26, 2017 4:11 am
How can I decode a url-encoded string as ujson() is unable to convert it and I urllib does not appear to have parse() method ?
Converts to:
Assuming that there is no built in library for this, is this the most efficient alternative:
Code: Select all
%7B%22_mode%22:%22func%22,%22_name%22:%22download%22,%22file_path%22:%22main.py%22,%22update_host%22:%22192.168.0.35%22,%22update_port%22:3001%7D
Code: Select all
{"_mode":"func","_name":"download","file_path":"main.py","update_host":"192.168.0.35","update_port":3001}
Code: Select all
def urldecode(self,str):
dic = {"%21":"!","%22":'"',"%23":"#","%24":"$","%26":"&","%27":"'","%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%2F":"/","%3A":":","%3B":";","%3D":"=","%3F":"?","%40":"@","%5B":"[","%5D":"]","%7B":"{","%7D":"}"}
for k,v in dic.items(): str=str.replace(k,v)
return str