Forums

yfinance/finance requests erroring

I've been transitioning my flask app to pythonanwyhere and am on the final stretch. My only problem right now is dealing with yfinance. Although I'm on the free plan, according to do allowed Internet list, yahoo should be fine. I isolated the problem with this:

try:
    url = "https://query1.finance.yahoo.com/v7/finance/quote?symbols=F"
    response = requests.get(url)
    return jsonify({"status": response.status_code, "text": response.text[:200]})
except Exception as e:
    return jsonify({"error": str(e)})

which results with

{"status":429,"text":"Edge: Too Many Requests"}

The same issue happens with yfinance. Is there something I can do to fix this? Thank you in advance.

That looks like yahoo is rate-limiting requests. It doesn't seem to indicate what the criteria they are using to rate limit, so I don't know what you can do about it.

Yes, I understand that but am curious if this is a problem unique to me or just a problem with pythonanywhere. I've seen other forum posts where people have used yfinance successfully.

Also, I did want to note that when I ran a yfinance script in the pythonanywhere console, it worked fine. Only when on my Flask app did it not work,

It's not unique to you or to PythonAnywhere - it is a rate limit imposed by yahoo.