Forums

Flask and Elm - CORS rejection

I've just implemented a simple Flask server. I am using Elm as my front end to request JSON. The JSON displays fine when I open my site in my browser, however requesting my elm app, the javascript console says:

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

Is there a simple fix for this?

that doesn't sound like a pythonanywhere-specific problem. have you tried a general google for it?

I just fixed it using Flask-CORS. Also I was returning my JSON as a JSON array which may have added to my problem. Thanks for the response!

glad you figured it out! :)

i am calling my rest api from a anguler6 app, and it shows me a a "No 'Access-Control-Allow-Origin' header is present" problem. i tried to use "flask_cors" but, if i use "flask_cors" like this ---

from flask_cors import CORS; app = Flask(name); CORS(app);

my api in pythonanywhere just crushed.

what do you mean by your api is crushed? does your whole app fail with 502s? or just your api requests return 403? what are the error messages and stack traces?

whole app fail. Error code: Unhandled Exception

Look in your error and server logs to find tracebacks that you can use to start debugging your web app.