I have written an API using Python EVE framework. While trying to access the API from an AngularJS app it shows an error as shown below :
XMLHttpRequest cannot load http://127.0.0.1:5000/user/jay3dec. Request header field Authorization is not allowed by Access-Control-Allow-Headers.
In order to correct the above error I added the following to the settings.py
X_DOMAINS = '*'
X_HEADERS = 'Authorization'
Now the above error disappears and a new error shows in the console :
XMLHttpRequest cannot load http://127.0.0.1:5000/user/jay3dec. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8000' is therefore not allowed access.
But I have already added the X_DOMAINS = '*'
in my settings.py .
Here is the angularjs code:
$scope.validate = function() {
var encodedUserNameAndPassword = Base64.encode($scope.username + ':' + $scope.password);
$http.defaults.headers.put = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
'Access-Control-Allow-Headers': '*'
};
$http.defaults.headers.common['Authorization'] = 'Basic ' + encodedUserNameAndPassword;
$http({
method: 'GET',
url: 'http://127.0.0.1:5000/user/jay3dec'
}).
success(function(data, status, headers, config) {
console.log(data);
}).
error(function(data, status, headers, config) {
alert(data);
});
}
Can any spot what may be the issue