Tornado request.body

Joel James picture Joel James · May 9, 2013 · Viewed 51k times · Source

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.

Answer

Farray picture Farray · Jan 25, 2015

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)