I am using Angular AJAX call to send data to my Flask backend for natural language processing.
AJAX code:
$scope.processText = function(){
$http({
method: "POST",
url: "http://127.0.0.1:5000/processText",
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json',
},
data: {
'message': "this is my message",
}
}).then(function successCallback(response){
console.log(response.data)
$scope.message = "";
});
}
I'm able to retrieve an Object {message: "this is my message"} but unfortunately I'm could not access to the key by typing request.data.message.
Flask route
@app.route('/processText', methods=['POST'])
def analyzeText():
if request.method == "POST":
data = json.loads(request.data)
return data #error : "dict is not callable"
return data.message #error : "'bytes' object has no attribute 'message'"