My Tornado application accepts POST data through http body request
In my handler I am able to get the request
def post(self):
data = self.request.body
The data I am getting is in the from of str(dictionary)
Is there a way to receive this data in the form of a Python dictionary?
I don't want to use eval
on the server side to convert this string to a Python dictionary.
Best way for me to parse body in tornado built-in
httputil
Good work with multi input (like checkbox, tables, etc.). If submit elements have same name in dictionary returning list of values.
Working sample:
If you are using WebApp2, it uses its own json extras. (Decode) http://webapp2.readthedocs.io/en/latest/_modules/webapp2_extras/json.html
For example my post key is 'postvalue'
how about
You are receiving a JSON string. Decode it with the JSON module
For more info: http://docs.python.org/2/library/json.html
As an alternative to Eloim's answer, Tornado provides tornado.escape for "Escaping/unescaping HTML, JSON, URLs, and others". Using it should give you exactly what you want:
I think I had a similar issue when I was parsing requests in Tornado. Try using the urllib.unquote_plus module:
My code had to be prepared for both different formats of request, so I did something like: