1
@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')])//

I want to get dictionary data. What is the request method I have to use?

davidism
  • 121,510
  • 29
  • 395
  • 339
Ratha
  • 9,434
  • 17
  • 85
  • 163

1 Answers1

2

Call to_dict on the 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'}
phihag
  • 278,196
  • 72
  • 453
  • 469
  • Why isn't the 'true' converted to Python boolean 'True' while doing `imd.to_dict()`? I have gone through all of stackoverflow answers but haven't found an answer. – Romit Aug 01 '20 at 14:59
  • @RomitThat sounds like a great question. Why don't you [ask it](https://stackoverflow.com/questions/ask)? Feel free to [drop me the URL](https://phihag.de/) – phihag Aug 01 '20 at 19:04
  • I am quite new to SO any help would be much appreciated. :) Link to question: https://stackoverflow.com/questions/63214893/how-to-convert-form-response-data-to-python-dictionary-in-flask – Romit Aug 02 '20 at 10:26