I have configured swagger UI using flask in python, swagger is having multiple end points which needs to be invoked at different server(not localhost) , but I am facing the CORS issue every time I try to invoke any endpoint , Swagger is running on Windows and the endpoints are also opened at windows.
Most of the time I am getting below error message
Access to fetch at ‘https://XXXXXXXXXXXXX.XX/’ from
origin ‘https://XX.XX.XX.X:40’ has been blocked by CORS policy:
Response to preflight request doesn’t pass access control check: No
‘Access-Control-Allow-Origin’ header is present on the requested
resource. If an opaque response serves your needs, set the request’s
mode to ‘no-cors’ to fetch the resource with CORS disabled.
I have tried below mentioned things :
- Used flask_cors library
from flask_cors import CORS, cross_origin
app = Flask(__name__)
api = Api(app)
CORS(app)
2.Tried setting up allow_headers with CORS
from flask_cors import CORS, cross_origin
app = Flask(__name__)
api = Api(app)
CORS(app, resources={r"/*": {"origins": "*"}}, allow_headers=["Content-Type", "api_key", "Authorization"])
-
Tried running flask on Http and Https both.
-
Explored multiple questions on internet but nothing works
I am struggling to find the solution for it,
PS: All the endpoints are easily getting invoked if I am using Postman.