Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

issue with flask-cors - blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status

I'm a newbie in flask and angular please bear with me.

I've been stuck with an issue about CORS. I've applied different code fixes just to make it work. Now the error that I am getting is

Access to XMLHttpRequest at 'http://localhost:5000/dashboard/clientscount/2019/2020' from origin 'http://localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.

I think the answer to my problem is from the answered question on this post: Has been blocked by CORS policy: Response to preflight request doesn’t pass access control check, specifcally this code

if r.Method == "OPTIONS" {
    w.WriteHeader(http.StatusOK)
    return
}

but this is in go language. I'm working in flask. my question is how do I make this in flask? also in the reference answer, it says to respond to the initial request but I'm not sure how to proceed with that one.

If you could point me in the right direction or docs, I'd gladly appreciate it.

like image 785
chip Avatar asked Sep 06 '25 03:09

chip


1 Answers

As the comments on the link describes, if you have setup CORS in your application and still has the problem, possible is because your application is calling a path that may differ from the path that you register.

example:

Flask url: http://localhost:3000/api/v1/support-user/

Called url: http://localhost:3000/api/v1/support-user

Missing / at the end

You can ensure that the problem is this if you see in your logs that flask redirect the request with 308

https://github.com/corydolphin/flask-cors/issues/257

like image 118
rodrigolmti Avatar answered Sep 07 '25 20:09

rodrigolmti