deepak murthy
deepak murthy

Reputation: 411

Python Flask - No 'Access-Control-Allow-Origin'

i get this error when loading a json file :

Failed to load http://localhost/sandbox/data.json?_=1505732125859: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:5000' is therefore not allowed access.

#...
from flask_cors import CORS
app = Flask(__name__)
CORS(app, resources={r"/*": {"origins": "*"}})
@app.route('/')
def index():
    return render_template('index.html')

Tried this solution.. but still getting same error Javascript - No 'Access-Control-Allow-Origin' header is present on the requested resource

Upvotes: 0

Views: 11607

Answers (1)

Quentin
Quentin

Reputation: 943100

You've set the CORS permissions on the wrong server.

A webpage on http://localhost:5000 is making a request to http://localhost.

Your headers are granting permission to every site (*) to access the data on http://localhost:5000, but you are trying to access the data on http://localhost.

You need to set the CORS permissions on http://localhost instead.

This answer explains the background.

Upvotes: 3

Related Questions