question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting CORS preflight error even with flask cors initialized

See original GitHub issue

Hey guys, I’ve been trying to get flask_cors to work for over two weeks now, so thought that I would write an issue.

Here’s what is in the init.py file

app = Flask(__name__, static_url_path='/static')
app.config.from_pyfile('config.py')

cors = CORS(resources={
    r'/*': {
        'origins': [
            'http://localhost:8080'
        ]
    }
})

cors.init_app(app)

The error that I’m getting is:

login?redirectNotebook=rose.intro:1 Access to XMLHttpRequest at 'http://localhost:5000/users' 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.

Went into the library to poke around and it looks like the after request isn’t being called. The backend is running on localhost:5000 and the frontend is running on localhost:8080, any help would be greatly appreciated!

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:3
  • Comments:20

github_iconTop GitHub Comments

14reactions
shrhawk-entertainercommented, Jul 21, 2021

@Elynad what I did is

from flask import Response

@current_app.before_request
def basic_authentication():
    if request.method.lower() == 'options':
        return Response()
1reaction
ryanbrwrcommented, Jul 15, 2021

I gave up a long time ago and used a different lib, appreciate it though.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python/Flask Rest API not passing preflight w/CORS
I am trying to get the simplest rest api ...
Read more >
Flask-CORS — Flask-Cors 3.0.10 documentation
A Flask extension for handling Cross Origin Resource Sharing (CORS), making cross-origin AJAX possible. This package has a simple philosophy: when you want...
Read more >
Flask-Cors Documentation - Read the Docs
In the simplest case, initialize the Flask-Cors extension with default arguments in order to allow CORS for all domains on all routes.
Read more >
Fix Flask CORS Error: Access-Control-Allow-Origin - YouTube
FULL STACK COURSE (React, Flask, & PostgreSQL): https://lukepeters.me/build-a-full-stack-web-app-with-react- flask -and-postgresqlCORS stands ...
Read more >
flask has been blocked by cors policy: no 'access-control ...
Old Answer · from flask import Flask from flask_cors import CORS app = Flask(__name__) CORS(app) · Access to XMLHttpRequest at 'http://host:5006/api/v1.0/group/? ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found