I'm trying to have my client-side Javascript code send post requests to my backend in Flask and I've used this answer issue with flask-cors - blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status but I still keep on getting this error
Here is my client side code
axios
.post(`http://127.0.0.1:5000/tags/`, {
image: srcUrl
})
.then(function(response) {
console.log(response);
})
.catch(function(error) {
console.log(error);
});
Here is my backend
from imageai.Classification import ImageClassification
import os
from flask import Flask
from flask_cors import CORS, cross_origin
app = Flask(__name__)
cors = CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'
@app.route('/')
@cross_origin()
def hello_world():
return {"What's": "up"}
@app.route('/tags')
@cross_origin()
def put_tags(image):
execution_path = os.getcwd()
prediction = ImageClassification()
# prediction.setModelTypeAsResNet50()
# prediction.setModelTypeAsInceptionV3()
prediction.setModelTypeAsDenseNet121()
prediction.setModelPath(os.path.join(
execution_path, "DenseNet-BC-121-32.h5"))
prediction.loadModel()
predictions, probabilities = prediction.classifyImage(
os.path.join(execution_path, image), result_count=5)
final = []
for eachPrediction, eachProbability in zip(predictions, probabilities):
final.append(eachPrediction)
return {'tags': final}