Я пытаюсь получить запрос XHR GET на API на основе Python-колбу и получаю эту ошибку:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://..... (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
Код сервера:
from flask_restful import Api
from flask_cors import CORS
application_root = config.get_application_root()
static_folder = os.path.join(application_root, 'static')
template_folder = os.path.join(application_root, 'templates')
app = Flask(__name__, static_url_path='/static', static_folder=static_folder, template_folder=template_folder)
cors = CORS(app)
app.config['SQLALCHEMY_DATABASE_URI'] ='mysql://*********'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['PROPAGATE_EXCEPTIONS'] = True # To allow flask propagating exception even if debug is set to false on app^M
api = Api(app)
@app.after_request
def after_request(response):
response.headers.add('Access-Control-Allow-Origin', '*')
response.headers.add('Access-Control-Allow-Headers', 'Content-Type,Authorization')
response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE')
return response
api.add_resource(TestResults, '/results')
if __name__ == '__main__':
db.init_app(app)
app.run(host='0.0.0.0', debug=True) # important to mention debug=True^M
Заголовок ответа все еще не получает требуемый заголовок.
Content-Length 2452
Content-Type application/json
Date Tue, 06 Nov 2018 06:52:06 GMT
Server Werkzeug/0.14.1 Python/3.4.7
Что мне здесь не хватает ...