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.
Python Tornado Request Performance.md Meaning tornado will be able to handle a maximum of 10 simultaneous fetch() operations in parallel on each IOLoop. This means a single tornado process should only be able to handle ~3 incoming requests before subsequent ones would queue in Tornado's AsyncHTTPClient.
A Tornado web application generally consists of one or more RequestHandler subclasses, an Application object which routes incoming requests to handlers, and a main() function to start the server.
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:
data = tornado.escape.json_decode(self.request.body)
You are receiving a JSON string. Decode it with the JSON module
import json def post(self): data = json.loads(self.request.body)
For more info: http://docs.python.org/2/library/json.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With