Question

Flask app: CORS header ‘Access-Control-Allow-Origin’ missing, having cors() enabled,and many requests goes through

Hi,when my request is for little data,i have no errors and status 200,but when i do requests that responds more data -> yahoo finance does more requests,i get the CORS error. This is the api url https://jjtrading-yzukr.ondigitalocean.app/api/minsmax?days_back=2d&coins_quantity=2 ,when i request little coins (2) its no problem,but if i request: https://jjtrading-yzukr.ondigitalocean.app/api/minsmax?days_back=2d&coins_quantity=50 (50 coins) ,i get the CORS error. Here is my flask app:

from utils import *
from flask_cors import CORS, cross_origin
from flask import Flask, request, jsonify

app = Flask(__name__)
cors = CORS(app)

@app.route('/')
@cross_origin()
def index():
    return "Home"

@app.route('/api', methods=['GET'])
@cross_origin()
def api():
    return{
        "tutorial": "Flask React Herokuu"
    }

@app.route('/api/minsmax', methods=['GET'])
@cross_origin(headers=['Content-Type', 'Authorization'])
def prices():
    days_back = request.args.get('days_back')
    coins_quantity = request.args.get('coins_quantity')
    response = jsonify(get_coins_in_min_max(days_back, coins_quantity))
    return response


@app.route('/api/minsmax/coinsexcluded', methods=['GET'])
@cross_origin()
def coins_excluded():
    return json.dumps(coins_exceptions)


@app.route('/api/minsmax/addcoin/', methods=['PUT'], strict_slashes=False)
@cross_origin()
def add_coin():
    coin = request.args.get('coin')
    coins_exceptions.append(coin)
    response = json.dumps(coins_exceptions)

    return response


if __name__ == '__main__':
    app.run()

Any idea what can be the issue? thanks!


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi there,

Keep in mind that you might also have to configure your App Platform CORS Policies as described in the documentation here:

https://docs.digitalocean.com/products/app-platform/how-to/configure-cors-policies/

If this still does not work, can you share the complete error that you are getting?

Best,

Bobby