Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access to XMLHttpRequest at 'http://...' from origin 'http://localhost:8000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request. #257

Open
jennykwan opened this issue Dec 6, 2019 · 9 comments

Comments

@jennykwan
Copy link

I'm getting the following error when using axios in redux-saga in react to post a multipart/form-data:

Access to XMLHttpRequest at 'http://...' from origin 'http://localhost:8000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.

My Flask-CORS config is dead simple:

app = flask.Flask(__name__)
flask_cors.CORS(app)

I see nothing in the docs referencing any non-default options to pass preflight checks for origin '*'. I'm not using cookies. What am I missing?

@haibeey
Copy link

haibeey commented Jan 29, 2020

you probably want to @cross_origin() decorators to your routes

@mukeshsharma1201
Copy link

I am getting the same issue. I tried using supports_credentials , expose_headers , allow_headers. Nothing seems to help.

@victorct-pronto
Copy link

We are getting the same issue, any update on this, it happens randomly

@HarpSun
Copy link

HarpSun commented Jul 2, 2020

I have hit the same issue recently, and at last I found it was caused by the unmatch of request url.
For example, at flask, I claim a url as this

@app.route('/user/', methods=['GET'])

but the url frontend requesting is '/user',this will cause the flask returned a 308 redirect response which is not allowed by
Cors preflight request.

So the conclusion is making the backend url and frontend url stricly match will solve the problem. I hope this helps.

@sanjeev0007
Copy link

Thanks @HarpSun it worked for me:)

@mukeshsharma1201
Copy link

mukeshsharma1201 commented Jul 9, 2020

can confirm, @HarpSun solution works!

@hans2520
Copy link

I have hit the same issue recently, and at last I found it was caused by the unmatch of request url.
For example, at flask, I claim a url as this

@app.route('/user/', methods=['GET'])

but the url frontend requesting is '/user',this will cause the flask returned a 308 redirect response which is not allowed by
Cors preflight request.

So the conclusion is making the backend url and frontend url stricly match will solve the problem. I hope this helps.

You can also try @app.route('/user/', methods=['GET'], strict_slashes=False) to make this work without getting the 308 response.

@johnarumemi-qs
Copy link

I have hit the same issue recently, and at last I found it was caused by the unmatch of request url.
For example, at flask, I claim a url as this

@app.route('/user/', methods=['GET'])

but the url frontend requesting is '/user',this will cause the flask returned a 308 redirect response which is not allowed by
Cors preflight request.
So the conclusion is making the backend url and frontend url stricly match will solve the problem. I hope this helps.

You can also try @app.route('/user/', methods=['GET'], strict_slashes=False) to make this work without getting the 308 response.

for app wide configuration of this try:

app.url_map.strict_slashes = False

Thanks for the solution @hans2520 , that led me to this solution I found elsewhere.

@Rodrigolmti
Copy link

Rodrigolmti commented Dec 18, 2021

I have hit the same issue recently, and at last I found it was caused by the unmatch of request url. For example, at flask, I claim a url as this

@app.route('/user/', methods=['GET'])

but the url frontend requesting is '/user',this will cause the flask returned a 308 redirect response which is not allowed by Cors preflight request.

So the conclusion is making the backend url and frontend url stricly match will solve the problem. I hope this helps.

I hope more people see your response, there is several links and issues open about this problem and none of them mention this. This solve my problem.

I started to get this error after migrating my api's to blueprints, and didn't notice that the path was different.

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants