yfinance: HTTP Error 401 for Ticker upgrades_downgrades, info, etc
Describe bug
I am using yfinance.Ticker class to fetch upgrades_downgrades for a stock. Getting “HTTP error 401” for this. This worked fine yesterday. Seems to be something from last evening. I don’t access this very frequently, maybe once or twice a day, so does not appear to be rate based blocking etc. I have able to see the data at Yahoo Finance website as well.
Simple code that reproduces your problem
import yfinance as yf
print(yf.__version__)
yf.enable_debug_mode()
df = yf.Ticker(symbol).upgrades_downgrades.reset_index()
Debug log from yf.enable_debug_mode()
0.2.63 DEBUG get_raw_json(): https://query2.finance.yahoo.com/v10/finance/quoteSummary/AMZN DEBUG Entering get() DEBUG Entering _make_request() DEBUG url=https://query2.finance.yahoo.com/v10/finance/quoteSummary/AMZN DEBUG params={‘modules’: ‘upgradeDowngradeHistory’, ‘corsDomain’: ‘finance.yahoo.com’, ‘formatted’: ‘false’, ‘symbol’: ‘AMZN’} DEBUG Entering _get_cookie_and_crumb() DEBUG cookie_mode = ‘basic’ DEBUG Entering _get_cookie_and_crumb_basic() DEBUG Entering _get_cookie_basic() DEBUG Entering _load_cookie_curlCffi() DEBUG Exiting _load_cookie_curlCffi() DEBUG reusing persistent cookie DEBUG Exiting _get_cookie_basic() DEBUG Entering _get_crumb_basic() DEBUG Entering _get_cookie_basic() DEBUG reusing cookie DEBUG Exiting _get_cookie_basic() DEBUG crumb = ‘75nzMgqhILN’ DEBUG Exiting _get_crumb_basic() DEBUG Exiting _get_cookie_and_crumb_basic() DEBUG Exiting _get_cookie_and_crumb() DEBUG response code=401 DEBUG toggling cookie strategy basic -> csrf DEBUG Entering _get_cookie_and_crumb() DEBUG cookie_mode = ‘csrf’ DEBUG Entering _get_crumb_csrf() DEBUG Entering _get_cookie_csrf() DEBUG Entering _load_cookie_curlCffi() DEBUG Exiting _load_cookie_curlCffi() DEBUG reusing persistent cookie DEBUG Exiting _get_cookie_csrf() DEBUG crumb = ‘75nzMgqhILN’ DEBUG Exiting _get_crumb_csrf() DEBUG Exiting _get_cookie_and_crumb() DEBUG response code=401 DEBUG Exiting _make_request() DEBUG Exiting get() ERROR HTTP Error 401:
Bad data proof
No response
yfinance version
0.2.63
Python version
3.13.4
Operating system
ProductName:macOS ProductVersion:15.4.1 BuildVersion:24E263
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 1
- Comments: 69 (12 by maintainers)
No you don’t. yfinance survives because people volunteer their own time to fix and improve. Nothing is expected.
Also, this thread conversation is what “working on it” looks like.
First time I got that message back from the API:
Interesting… has someone else seen this before?
An with Premium ( Selenium ) I see Captachas now… running in non-Headless mode. Does someone know which subscription would help?
@ValueRaider @sublinn @sanyearng
This appears to be an issue on Yahoo’s end. If you trace the execution, you’ll see that the
401 Unauthorizedstatus code originates from the get request on this line is not raised by theyfinance. Furthermore, as both I and @lhjnilsson have verified through testing in the browser and using curl, the issue persists independently ofyfinance, indicating that the root cause lies with Yahoo’s service itself.I see the APIs are succeeding now. Not sure for how long. Will check till tomorrow, and it things are fine, will close the issue. Others please confirm if you are seeing same behavior as well.
Update: I have more than 5 days without any 401 error
Great news, I just had a perfect run. It was a fairly large batch, too. No 401 error’s, and all attributes attempted to retrieve (such as: option chain, insiders & institutional ownership, analysts ratings, and more) returned all requested values. That latter part is important because the previously experienced inconsistencies with the data being returned went hand in hand with the 401 errors, in my experience.
I will be running this again at some point today, and can provide further feedback.
Haha, nice. I was testing, per prior comment, not normal operation. But for further clarity, it was .ticker().info that I was retrieving as, in my experience, the throttling occurs for the general .ticker() call. My actual end use info is not “upgrades_downgrades”, and my comments relate to general .ticker() calls.
In my case, I have noticed the problem is more frequent during regular market hours. The error is gone at night, when the market is close. Right now, I don’t see the error, but I bet it will be present tomorrow again
I am still getting this. What argument should I be using for “session”? I got an output at one point that told me I shouldn’t be using it at all any more.
It also doesn’t throw an exception. It just prints the text “HTTP Error 401:” and keeps going
401’s are still occurring. The two issues might be related, might not. Doesn’t change that 401’s are still occurring.
@sublinn Raise new issue. And improve formatting, no one’s reading that message
For further colour, even repeated “low usage” can trigger this error.
I use yfinance.ticker().info to get amongst other things, basic security currencies for plotting ccy-translated plots. A manually repeated call of this function for, as an example, only 3 securities triggers what I assume (and per @melgazar9) is a rate-limiting error. This happens on many occasions when the function call is repeated some full seconds later. This is not an example of heavy use and hundreds/thousands of tickers being called. Even low use seems to be triggering this.
FWIW I think this is actually supposed to be a rate limit error. It’s difficult to debug missing data because the yfinance library logs 401 to stdout by default rather than raising a 429 error. I’m thinking there might be one of two things (and it’s not just for upgrades_downgrades, it happens for all methods —> sec_filings, actions, option_chain, etc).
Possibilities:
yahoo is actually sending a 401 error and the log message is correct, but the real reason for the 401 is actually from too many requests.
Yahoo is sending a 429 error (or some other code) that implies rate limiting, but yfinance may have a bug routing that message to 401?
In both case i’d recommend raising the 401 error instead of logging it to stdout.
https://github.com/ValueRaider/yfinance-cache
When pulling down the list of holdings for a ticker I get a 401 error one the first or second ticker I pull down. I’ve even added 5 to 60 second delays between queries, still same issue. This started at about 4:30 PM Eastern time today.
`tickerData = yfinance.Ticker(ticker)
topHoldings = tickerData.get_funds_data().top_holdings`
yFinance 0.2.63 Python 3.12.3
DEBUG get_raw_json(): https://query2.finance.yahoo.com/v10/finance/quoteSummary/MFEKX DEBUG Entering get() DEBUG Entering _make_request() DEBUG url=https://query2.finance.yahoo.com/v10/finance/quoteSummary/MFEKX DEBUG params={‘modules’: ‘quoteType,summaryProfile,topHoldings,fundProfile’, ‘corsDomain’: ‘finance.yahoo.com’, ‘symbol’: ‘MFEKX’, ‘formatted’: ‘false’} DEBUG Entering _get_cookie_and_crumb() DEBUG cookie_mode = ‘basic’ DEBUG Entering _get_cookie_and_crumb_basic() DEBUG Entering _get_cookie_basic() DEBUG Entering _load_cookie_curlCffi() DEBUG Exiting _load_cookie_curlCffi() DEBUG reusing persistent cookie DEBUG Exiting _get_cookie_basic() DEBUG Entering _get_crumb_basic() DEBUG Entering _get_cookie_basic() DEBUG reusing cookie DEBUG Exiting _get_cookie_basic() DEBUG crumb = ‘OV.ptrOCi0z’ DEBUG Exiting _get_crumb_basic() DEBUG Exiting _get_cookie_and_crumb_basic() DEBUG Exiting _get_cookie_and_crumb() DEBUG response code=200 DEBUG Exiting _make_request() DEBUG Exiting get() Getting: FOKFX DEBUG get_raw_json(): https://query2.finance.yahoo.com/v10/finance/quoteSummary/FOKFX DEBUG Entering get() DEBUG Entering _make_request() DEBUG url=https://query2.finance.yahoo.com/v10/finance/quoteSummary/FOKFX DEBUG params={‘modules’: ‘quoteType,summaryProfile,topHoldings,fundProfile’, ‘corsDomain’: ‘finance.yahoo.com’, ‘symbol’: ‘FOKFX’, ‘formatted’: ‘false’} DEBUG Entering _get_cookie_and_crumb() DEBUG cookie_mode = ‘basic’ DEBUG Entering _get_cookie_and_crumb_basic() DEBUG Entering _get_cookie_basic() DEBUG reusing cookie DEBUG Exiting _get_cookie_basic() DEBUG Entering _get_crumb_basic() DEBUG reusing crumb DEBUG Exiting _get_crumb_basic() DEBUG Exiting _get_cookie_and_crumb_basic() DEBUG Exiting _get_cookie_and_crumb() DEBUG response code=401 DEBUG toggling cookie strategy basic -> csrf DEBUG Entering _get_cookie_and_crumb() DEBUG cookie_mode = ‘csrf’ DEBUG Entering _get_crumb_csrf() DEBUG Entering _get_cookie_csrf() DEBUG Entering _load_cookie_curlCffi() DEBUG Exiting _load_cookie_curlCffi() DEBUG reusing persistent cookie DEBUG Exiting _get_cookie_csrf() DEBUG crumb = ‘OV.ptrOCi0z’ DEBUG Exiting _get_crumb_csrf() DEBUG Exiting _get_cookie_and_crumb() DEBUG response code=401 DEBUG Exiting _make_request() DEBUG Exiting get() Traceback (most recent call last): File “/home/BiggRanger/PycharmProjects/LibreOffice_StockTracker/main.py”, line 122, in <module> TestHolding() File “/home/BiggRanger/PycharmProjects/LibreOffice_StockTracker/main.py”, line 109, in TestHolding loadHoldings(tickersTest, os.path.expanduser(‘~’) + ‘/TickerHoldingsList.txt’) File “/home/BiggRanger/PycharmProjects/LibreOffice_StockTracker/main.py”, line 98, in loadHoldings topHoldings = tickerData.get_funds_data().top_holdings ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File “/home/BiggRanger/PycharmProjects/LibreOffice_StockTracker/.venv/lib/python3.12/site-packages/yfinance/scrapers/funds.py”, line 118, in top_holdings self._fetch_and_parse() File “/home/BiggRanger/PycharmProjects/LibreOffice_StockTracker/.venv/lib/python3.12/site-packages/yfinance/scrapers/funds.py”, line 185, in _fetch_and_parse result = self._fetch() ^^^^^^^^^^^^^ File “/home/BiggRanger/PycharmProjects/LibreOffice_StockTracker/.venv/lib/python3.12/site-packages/yfinance/scrapers/funds.py”, line 178, in _fetch result = self._data.get_raw_json(QUOTE_SUMMARY_URL+self._symbol, params=params_dict) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File “/home/BiggRanger/PycharmProjects/LibreOffice_StockTracker/.venv/lib/python3.12/site-packages/yfinance/data.py”, line 433, in get_raw_json response.raise_for_status() File “/home/BiggRanger/PycharmProjects/LibreOffice_StockTracker/.venv/lib/python3.12/site-packages/curl_cffi/requests/models.py”, line 167, in raise_for_status raise HTTPError(f"HTTP Error {self.status_code}: {self.reason}", 0, self) curl_cffi.requests.exceptions.HTTPError: HTTP Error 401:
I Agree. The same happens to me. If I retry later, it works.
Error 401 again here.
The 401 demon is back
@shamikganguly This package (yfinance) is an Unofficial library to scrape data using yahoo finance API. Yahoo Finance together with many other services went offline yesterday for a brief period. This probably caused some issues for Yahoo that took a while to recover. You are more than welcome to mail yahoo and try to get any response, again this library is unofficial so its very unlikely that they would say anything here. Meanwhile, this is probably related https://mashable.com/article/google-cloudflare-amazon-internet-outage-june-2025
My contribution: I confirmed error when bug report first posted, later worked once, then back to failing now.
The call depends on quoteHistory api endpoint of yahoo, seems like their own webpage is having issues reaching - with 401 error. Probably something happening out of this libraries control