Making Two Http Post Requests In Flask
I need to do two post request as shown in following code but only one POST is working,below is the python code : import json from flask import Flask, render_template, request, jso
Solution 1:
Both POSTs are probably working but you return after checking the first one.
if r.status_code == 200:
returnData["status"] = "SUCCESS"
returnData["result"] = json.loads(r.text)
return jsonify(returnData) # HEREelse:
returnData["status"] = "ERROR"return jsonify(returnData) # OR HEREif r1.status_code == 200:
returnData1["status"] = "SUCCESS"
returnData1["result"] = json.loads(r1.text)
return jsonify(returnData1) # You'd do it again here...else:
returnData1["status"] = "ERROR"return jsonify(returnData1) # ... or here
Instead, you need to collect both results and return them together.
if r.status_code == 200:
returnData["status"] = "SUCCESS"
returnData["result"] = json.loads(r.text)
else:
returnData["status"] = "ERROR"if r1.status_code == 200:
returnData1["status"] = "SUCCESS"
returnData1["result"] = json.loads(r1.text)
else:
returnData1["status"] = "ERROR"return jsonify(returnData=returnData, returnData1=returnData1)
Post a Comment for "Making Two Http Post Requests In Flask"