Python Flask Cors error – set according to documentation

Question:

I have created API using Flask in Python. Now I am trying to create front end, where I want to call API. I set CORS according Flask-Cors documentation, unfortunately it doesn’t work.

from flask_cors import CORS
CORS(app)

I got this error
CORS error – Safari

CORS error – Chrome

I have found some similar topics, where was some solution. I have tried, but neither of them work for me. E.g.

CORS(app, origins=['http://localhost:4200'])
app.config['CORS_HEADERS'] = 'Content-Type'

I have also tried cross_origin decorator, but it doesn’t work as well.

@app.route("/login", methods = ["POST"])
@cross_origin(origin='*')
def login():
    credentials = request.get_json()
    ....

Could someone help me, how to solve this problem?

Asked By: rumcajs

||

Answers:

Make sure the URL you are trying to access begins with 'http://' or 'https://' according to your web server’s configuration

Answered By: John Appleboim
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.