Jul-02-2023, 05:04 PM
(This post was last modified: Jul-02-2023, 05:04 PM by michaelnicol.)
Hello,
I am attempting to use Flask, but I am unable to configure CORS to allow for requests from other ports.
My current Python server:
I am attempting to use Flask, but I am unable to configure CORS to allow for requests from other ports.
My current Python server:
from flask import Flask, request from urllib.request import urlopen from flask_cors import CORS, cross_origin app = Flask(__name__) CORS(app, resources={r"/*": {"origins": "*"}}) app.config['CORS_HEADERS'] = 'Content-Type' @app.route('/', methods=['POST']) @cross_origin() def convert(): print("Received Request") print(request.json()) return "Success" if __name__ == "__main__": app.run()Despite this, any requests made to this localhost, from another port, with the following headers:
"method": "POST", "Access-Control-Allow-Origin": "*", "headers": { "Content-Type": "application/json" },Results in the following error:
Error:Access to fetch at 'http://localhost:5000/' from origin 'http://localhost:3000' 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.