I have this python code (file test.py
) that tries to handle an http POST request, I also have and index.html
file that gets correctly displayed (it's just a button that makes the http call), i run the server with python test.py
and when I click the button I get this error in console:
Access to fetch at 'http://127.0.0.1:8001/process_question' from origin 'http://localhost:8001' has been blocked by CORS policy: 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 thought I handled CORS correctly, but I guess I'm not, any suggestion on how to fix this?
from flask import Flask, request, jsonify, make_response, render_template
from flask_cors import CORS
import requests
import os
import PyPDF2
from transformers import pipeline
app = Flask(__name__)
api_cors_config = {
"origins": ["*"],
"methods": ["OPTIONS", "GET", "POST"]
}
CORS(app, resources={
r"/*": api_cors_config
})
@app.route('/process_question', methods=['POST'])
def process_question():
...
return ...
@app.route('/')
def home():
return render_template('index.html')
if(__name__ == "__main__"):
app.run(debug=True, port=8001)