如何从python中的请求中检索字典数据?

时间:2018-02-07 01:03:52

标签: python flask

@app.route('/ATGDataSubmission', methods=['POST'])
def ATGDataSubmissions(): 
           print request.data //prints none
           receivedData = request.form
           print receivedData // prints ImmutableMultiDict([('ErrorMessage', u'Not able to connect'), ('SiteId', u'12345'), ('CommandResult', u'201'), ('IsSuccessfull', u'true')])//

我想获取字典数据。我必须使用哪种请求方法?

1 个答案:

答案 0 :(得分:2)

致电to_dict上的ImmutableMultiDict

>>> imd = ImmutableMultiDict([('ErrorMessage', u'Not able to connect'),
('SiteId', u'12345'), ('CommandResult', u'201'), ('IsSuccessfull', u'true')])
>>> imd.to_dict()
{'ErrorMessage': 'Not able to connect', 'SiteId': '12345', 'CommandResult': '201',
 'IsSuccessfull': 'true'}