in the below posted webservice, i obtain the data posted from the front-end using json.loads
the result of the print statment is posted below in the sample-data section.
the problem i have is when i try to obtain the values included in the request.data
, for example, treatmentGeometryAsJSONInEPSG3857
. the error i am getting when i run the code is:
treatmentAsGeoJSONInEPSG3857 = json.loads(request.data)['body'][config['FRONT_END_KEYS']['key_treatmentGeometryAsJSONInEPSG3857']]
TypeError: string indices must be integers
please let me know how to access the contents of the posted request
i referred to the following posts as well but none contains an answer to my question
https://stackoverflow.com/questions/10434599/get-the-data-received-in-a-flask-request
https://www.digitalocean.com/community/tutorials/processing-incoming-request-data-in-flask-de
code:
@app.route("/experimentExistenceCheck/", methods=['POST','OPTIONS'])
def experimentExistenceCheck():
preFlight = FlaskAccessControlUtils.preFlightCheck(request)
if preFlight: return preFlight
data = json.loads(request.data)['body']
print("--------->",data)
treatmentAsGeoJSONInEPSG3857 = json.loads(request.data)['body'][config['FRONT_END_KEYS']['key_treatmentGeometryAsJSONInEPSG3857']]
selectedSiteId = json.loads(request.data)['body'][config['FRONT_END_KEYS']['selectedSiteID']]
threshold = json.loads(request.data)['body'][config['FRONT_END_KEYS']['threshold']]
visualizationOperationID = json.loads(request.data)['body'][config['FRONT_END_KEYS']['visualizationOperationID']]
print("--------->",treatmentAsGeoJSONInEPSG3857)
print("--------->",selectedSiteId)
print("--------->",threshold)
print("--------->",visualizationOperationID)
sample data:
{"threshold":"1","visualizationOperationID":2,"treatmentGeometryAsJSONInEPSG3857":"{\"coordinates\":[[[745037.9841857546,6644742.79192291],[744938.5789015774,6644804.979114908],[744973.912533394,6644856.330659814],[745025.2640783006,6644838.428286361],[745022.4373877553,6644802.623539453],[744997.9394030292,6644768.703252909],[745037.9841857546,6644742.79192291]]],\"type\":\"Polygon\"}","selectedSiteID":"202108041239"}