Access to XMLHttpRequest at ‘http://localhost:5000/check-password’ from origin ‘http://localhost:5173’ 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.
I dont understand what is the problem
`from flask import Flask, jsonify
from flask_cors import CORS, cross_origin
app = Flask(__name__)
CORS(app , origins="*")
@app.route('/', methods=['GET','OPTIONS'])
def hello_world(): # put application's code here
return 'Hello World!'
def check_password_strength(password):
if len(password) < 6:
return 'Weak'
elif any(char.isdigit() for char in password):
return 'Medium'
else:
return 'Strong'
@app.route('/check-password', methods=['POST', 'OPTIONS'])
def check_password(password: str):
strength = check_password_strength(password)
response = jsonify({'strength': strength})
response.headers.add("Access-Control-Allow-Origin", "*")
return response
if __name__ == '__main__':
app.run(debug=True)
`
And a simple code in React that use axios to send a post with the password
New contributor
Nathan Marciano is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.