Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Credentials' header in the response is '' which must be 'true' when the request's credentials mode is 'include'
See original GitHub issueNot sure why I’m getting this error when trying to allow CORS on my flask app. Here’s my server:
#library imports
from flask import Flask
from flask_cors import CORS, cross_origin
app = Flask(__name__)
CORS(app, resources={r"/*": {"origins": "*"}})
app.config['CORS_HEADERS'] = 'Content-Type'
@app.route('/img', methods=['POST'])
def image_upload():
if not request.json:
abort(400)
print(request.json)
return jsonify('working')
if __name__ == "__main__":
app.run(host= "0.0.0.0", debug=True, port = 5000, threaded=True)
print("Running dev server on port 5000")
Now on my frontend, when I attempt to make a POST request to /img
, I get the error in the title. The full error is:
XMLHttpRequest cannot load http://0.0.0.0:5000/img. Response to preflight request doesn’t pass access control check: The value of the ‘Access-Control-Allow-Credentials’ header in the response is ‘’ which must be ‘true’ when the request’s credentials mode is ‘include’. Origin ‘http://localhost:8080’ is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:10 (1 by maintainers)
Top Results From Across the Web
The credentials mode of requests initiated by ... - Stack Overflow
The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute. One of the request is like this ...
Read more >Yii2 does not send Access-Control-Allow-Headers in preflight ...
I extend ActiveController and set CORS filter in my application ... is not allowed by Access-Control-Allow-Headers in preflight response.
Read more >CORS policy | Apigee X - Google Cloud
Indicates whether the caller is allowed to send the actual request (not the preflight) using credentials. Translates to the Access-Control-Allow-Credentials ...
Read more >Authorization Code OAuth flow for SharePoint Add-ins
This section summarizes the OAuth authentication and authorization flow for a SharePoint add-in requesting permissions on the fly. The flow is ...
Read more >Error has been blocked by CORS policy: No 'Access-Control ...
My webapp API is running, and use OAuth with Spring-security to manage authentication with Salesforce OAuth2. Everything is OK if i'am using the ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Update: Adding the following code works, is there a way to do this with flask-cors so I don’t need to ways of allowing cross-origin?
@corydolphin I have the same error. I have built na application and If I test request using Postman or Insonia it works normally, the application receive the requests and store the data in the session / database, but if I try to make a request from a React application using Axios I receive an error and the application doesn’t receive any request or store data.
Error :
Failed to load 127.0.0.1:5000/logout : Response to preflight request doesn't pass access control check : The value of the ' Access-Control-Allow-Credentials ' header in the response is ' ' which must be ' true ' when the request's credentials mode is ' include '. Origin ' localhost:8080 ' is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.
Flask application config :
Request in React :
I have also research but I don’t know how to solve this.
Obs ¹ : I’m using server side session (Flask Session)
Obs ² : The other error is a 500. It happens because I try to get something from session to make the logout, but the attribute is not found in session (if I make the request with the tool I mentioned, it works fine).