Forums

Flask CORS is not solving CORS issue

I've installed Flask CORS on my pythonanywhere account per flask-cors.readthedocs.io using

pips3.6 install --user flask-cors

I've loaded it in my app using:

from flask_cors import CORS
app = Flask(__name__)
CORS(app)

But nothing! When I load the page, I still get CORS errors. There is no indication in the pythonanywhere that any of the modules are missing or anything.

Reading the documentation for flask-cors I got the impression that once up and running, any CORS errors should be resolved for all pages in the site.

How can I get this to work?

probably app = CORS(app)

Changing it to app = CORS(app) makes the app fail. It goes from serving the data to throwing this error:

Error code: Unhandled Exception

I think Conrad was mistaken in his suggestion. Could you give an example of a page on your site that is generating the CORS errors so that we can take a look?

I have resolved the issue. The issue was that I was loading CORS but I also was setting the headers in the cross-origin headers in JSON object. Removed that and now it works!

Ah, excellent -- glad you worked it out!