问题描述
我的 Tornado 应用程序通过 http body 请求接受 POST 数据
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
我得到的数据来自 str(dictionary)
The data I am getting is in the from of str(dictionary)
有没有办法以 Python 字典的形式接收这些数据?
Is there a way to receive this data in the form of a Python dictionary?
我不想在服务器端使用 eval
将此字符串转换为 Python 字典.
I don't want to use eval
on the server side to convert this string to a Python dictionary.
推荐答案
作为 Eloim 答案的替代方案,Tornado 提供了 tornado.escape 用于转义/取消转义 HTML、JSON、URL 和其他".使用它应该给你你想要的:
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)
这篇关于Tornado request.body的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!