yfinance: [0.2.57] YFRateLimitError('Too Many Requests
Describe bug
This error just returned on a query (2025-04-29). I’ve tried using different IP addresses, so it’s not my account hitting a rate limiter.
“Failed download: [‘^GSPC’]: YFRateLimitError(‘Too Many Requests. Rate limited. Try after a while.’)”
Simple code that reproduces your problem
yf.download(‘^GSPC’, multi_level_index=False)
Debug log from yf.enable_debug_mode()
YF.download() has changed argument auto_adjust default to True [100%**] 1 of 1 completed
1 Failed download: [‘^GSPC’]: YFRateLimitError(‘Too Many Requests. Rate limited. Try after a while.’)
Bad data proof
No response
yfinance version
0.2.57
Python version
3.10.4
Operating system
OSX
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 11
- Comments: 141
Commits related to this issue
- Fuck Yahoo - https://github.com/ranaroussi/yfinance/issues/2422#issuecomment-2840759533 - make sure you update your package — committed to varun-rao95/finances by varun-rao95 2 years ago
- Fuck Yahoo - https://github.com/ranaroussi/yfinance/issues/2422#issuecomment-2840759533 - make sure you update your package — committed to varun-rao95/finances by varun-rao95 2 years ago
- Fuck Yahoo - https://github.com/ranaroussi/yfinance/issues/2422#issuecomment-2840759533 - make sure you update your package — committed to varun-rao95/finances by varun-rao95 2 years ago
- Fuck my sloppy code & Yahoo - https://github.com/ranaroussi/yfinance/issues/2422#issuecomment-2840759533 - make sure you update your package — committed to varun-rao95/finances by varun-rao95 2 years ago
- fix a rate limit error per https://github.com/ranaroussi/yfinance/issues/2422#issuecomment-2840774505 — committed to zhuanyi/streamlit_backtester by zhuanyi 2 years ago
- Upgrading yfinance package yfinance = "^0.2.59" Reason: https://github.com/ranaroussi/yfinance/issues/2422 — committed to mongodb-industry-solutions/leafy-bank-backend-capitalmarkets-loaders by boroju 2 years ago
- Fix YFRateLimitError('Too Many Requests") https://github.com/ranaroussi/yfinance/issues/2422 — committed to clumdee/stockAlert by clumdee 2 years ago
This worked for me! FWIW, you can inject the session directly into yf.Ticker without needing to patch yfinance.
I think I figured out something useful
I noticed that (as one of the above comments mentioned as well) it works for me on a browser. It works with curl too. But somehow it just doesn’t work with the Python requests module (with identical headers in all tests), consistently getting 429.
At that point I was suspecting they implemented some kind of TLS fingerprinting mechanism. So I just looked up popular libraries that can impersonate a browser’s TLS fingerprints, and this is the one I went with. Seems to work well for me so far.
To be more exact, I just swapped out the session object on line 85 of data.py of this package, so that it looks something like this:
where
requestsis imported from curl_cffi insteadI was still getting an issue
Failed to get ticker 'SPY' reason: 'str' object has no attribute 'name'and this works for me.Note, if you are getting empty results, make sure you set
raise_errors=Trueto see the error.You’ll need to install
curl_cffi:yfinance_cookie_patch.py
demo.py
Quicker fix without monkey patching, sort of.
pip uninstall yfinance pip install git+https://github.com/bretsky/yfinance.git@fix/curl-cffi-cookies
No other changes needed to your old code.
I fixed rate limit issue with above work-around, but started this morning I am getting “$MSFT: possibly delisted; no price data found (period=1d)” when download stock prices, is it me or anyone else getting the sam error when you download prices? Please let me know Thanks.
release out
Same here. Tried several different versions/ headers.
curl_ffi.Session failed to work starting from less than hour ago…
0.2.59 & 3.11.8 , still not work, YFRateLimitError(‘Too Many Requests. Rate limited. Try after a while.’) somebody can help
A rather irritating failure after having worked fine for quite a while. Me, as always, from less to more. Working again without any issues 😃
Found existing installation: yfinance 0.2.54 Uninstalling yfinance-0.2.54: installed yfinance-0.2.59
Thanks @codyfletcher, @nmckoy . The cookies patch works on Lambda now with the
proxyparameter added to the_patchfunction.Looks like the signature for the
originalmethod isdef _get_crumb_basic(self, proxy=None, timeout=30). Try updating the _patched function to:Solution
All you need to do is to upgrade your yfinance
pip install --upgrade yfinanceGetting error with latest version of yfinance.
data = yf.download(ticker, period='6mo', interval='1d', auto_adjust=True, progress=True, multi_level_index=False)` [100%**] 1 of 1 completed
1 Failed download: [‘SPY’]: YFRateLimitError(‘Too Many Requests. Rate limited. Try after a while.’) downloading sector data [100%**] 1 of 1 completed
1 Failed download: [‘XLV’]: YFRateLimitError(‘Too Many Requests. Rate limited. Try after a while.’) [100%**] 1 of 1 completed`
Update yfinance to latest version; it now uses
requests.Session(impersonate="chrome")fromcurl_cffias default when nosessionparam is used for aTickerI updated to 0.2.59 and it works perfectly now.
That worked for me also, i.e. upgrading to 0.2.58. Strangely, updating to the HEAD didn’t!!
Hi All, Thanks for your effort to fix this issue. On my end i use Python 3.9.6 and i updated the yfinance to 0.2.58 after seeing a release hoping it will fix my issue unfortunately im still having the same Rate exceeded error. data.py mentioned is already changed with respect to the mentioned fix suggestions but issue is still going on on my end.
Many thanks to all great developers who gets many blessings from me everyday for developing the best open source library.
I tried setting my Session object to None instead, and that fixed the bug for me.
Maybe the rate limiters are now included by default in the Ticker object, so when you set another one in Ticker(), one rate-limiter is interfering with the other, idk.
FTR,
curldoesn’t seem to work now, either… 😦curl -v "https://query1.finance.yahoo.com/v8/finance/chart/AAPL"No. This should work - requests work but nothing written to cache DB:
So I tried the patch recommended here, but when I ran it I got the error::
1 Failed download: ['ADIL']: AttributeError("'str' object has no attribute 'name'")My best guess is that this is the cookie variable on line 217 of data.py getting assigned the ticker string, but I have no idea how just changing the session to
impersonate = 'chrome'would do that.I am running into a strange issue. The code works perfectly well on my windows machine, when I upload to an AWS ami and run it I get the following error when calling the ticker:
Failed to get ticker ‘MSFT’ reason: impersonate chrome is not supported UNCAUGHT ERROR: Could not get ticker info *** MOVING ON *** <class ‘curl_cffi.requests.errors.RequestsError’>
*** I figured out the issue, I was running this code on an older AMI instance. Even with all the latest updates it sttill could not do impersonation. Migrating all the code to a new AMI with latest Amazon Linux solved this ***
This thread is getting noisy now with the yfinance update. A mix of different discussions: new problems with
curl_cffi, rate error still happening, or PIP update problems. Please move your specific problem to the relevant issue thread - create if doesn’t exist. Probably I will lock this.I was in the same exact boat; try directly using the
curl_cffipackage as suggested by @alindsaydiazHi everyone!
I’m facing an issue with yfinance now, in which I can’t bring more than 20 downloads at a time. I’m running a process that needs currency conversion for near to 40 currencies for a specific date, but it always fails after the 20th attempt, with the YFRateLimitError. I tried using session but it doesn’t solve it. This worked perfectly fine before. I’m using yfinance 0.2.59 and python 3.11.
Hi All, I fixed the issue by not using session anymore. I use 0.2.59 and python 3.10 Previously:
Now it works without the session
stock_data = yf.download(symbol, start=sdate, end=edate, progress=False)import yfinance as yf from curl_cffi import requests
session = requests.Session(impersonate=“chrome”) symbol_spx = “^GSPC” symbol_es = “ES=F” spx_data = yf.Ticker(symbol_spx, session=session).history(interval=‘5m’, period=‘1mo’, auto_adjust=False) es_data = yf.Ticker(symbol_es, session=session).history(interval=‘5m’, period=‘1mo’, auto_adjust=False)
I upgraded my yfinance to yfinance-0.2.58, also tried the curl_cffi. But I still get
yfinance.exceptions.YFRateLimitError: Too Many Requests. Rate limited. Try after a while.Updating my yfinance package to latest release installed curl_cffi and fixed my problem. Guess the above fix was incorporated.
yes, or create a curl_cffi session like session = requests.Session(impersonate=“chrome”)
i confirm that setting session to either none or a custom curl_cffi session with chrome impersonation works
My suspicion is problem is yfinance still setting user-agent, shouldn’t curl_cffi be handling that? A quick test seems to confirm this.
Even after upgrading to 0.2.58 still doesn’t work
Yeah - solution is pip install --upgrade yfinance
This worked for me,
pip install --upgrade yfinance
seems work for me
This fix works for me, but cache won’t work any more. it seem the Session from curl_cffi.requests don’t support cache. previous the Session was from requests and support the CacheMixin
Thank you for the new release. 0.2.58 fixes the yf.download errors in both python 3.9.13 and 3.13.3.
Here is a PR #2434 that can fix this issue elegantly. You can add
git+https://github.com/irgb/yfinance.git@4bc7eb174f14c4c668fd2bf94b865717797b4ea7#egg=yfinanceto your requirements.txt before it’s merged into main repo.Looks like Yahoo made change again? Everything worked again, I no longer get “stock delisted” errors and (“‘str’ object has no attribute ‘name’”), but I still have curl_cffi work-around in place locally.
I used the fix listed below in yf.download(…). It worked in python 3.9.13 on one PC, however failed to work on 3.13.3 on another PC. When it fails, it gives the result: (“‘str’ object has no attribute ‘name’”).
Has anyone managed to get this to work for multiple items? I still keep getting
reason: 'str' object has no attribute 'name'even after patching. I’m also getting this after some changes:reason: Expecting value: line 1 column 1 (char 0)I am having the same issue on GCP. If I run the code from jupyter notebook no problem, if I run it from docker it returns empty
Perfect … that did it!!
Thanks nmckoy!!
I am following (https://github.com/ranaroussi/yfinance/issues/2422#issuecomment-2840774505) above, but getting empty dataframe for today’s data.
Thought I should try Cody’s solution, but my error is
TypeError('patch_yfdata_cookie_basic.<locals>._patched() takes from 1 to 2 positional arguments but 3 were given')Do you see what I am missing?
Windows 10 python 3.10 yfinance & curl-cffi latest
Thank you Cody!
this works like a charm. can we make this the default setting?
same issue here