ranaroussi / yfinance

Download market data from Yahoo! Finance's API
https://aroussi.com/post/python-yahoo-finance
Apache License 2.0
14.93k stars 2.45k forks source link

Got KeyError: 'insiderTransactions' when invoke get_major_holders() #1893

Open kncxstudio opened 8 months ago

kncxstudio commented 8 months ago

Describe bug

Got KeyError: 'insiderTransactions' when invoke get_major_holders()

image

It seems that _fetch_and_parse() return data that does not contain "insiderTransactions" any more.

Simple code that reproduces your problem

def ticker_employees(symbol): result = yf.Ticker(symbol,proxy=local_proxy,session=session).get_major_holders().to_dict() return Response(result)

Debug log

Traceback (most recent call last): File "/home/kn/PyProjects/ticker-api/.venv/lib/python3.10/site-packages/yfinance/scrapers/holders.py", line 103, in _fetch_and_parse self._parse_insider_transactions(data["insiderTransactions"]) KeyError: 'insiderTransactions'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/kn/PyProjects/ticker-api/.venv/lib/python3.10/site-packages/flask/app.py", line 2552, in call return self.wsgi_app(environ, start_response) File "/home/kn/PyProjects/ticker-api/.venv/lib/python3.10/site-packages/flask/app.py", line 2532, in wsgi_app response = self.handle_exception(e) File "/home/kn/PyProjects/ticker-api/.venv/lib/python3.10/site-packages/flask/app.py", line 2529, in wsgi_app response = self.full_dispatch_request() File "/home/kn/PyProjects/ticker-api/.venv/lib/python3.10/site-packages/flask/app.py", line 1825, in full_dispatch_request rv = self.handle_user_exception(e) File "/home/kn/PyProjects/ticker-api/.venv/lib/python3.10/site-packages/flask/app.py", line 1823, in full_dispatch_request rv = self.dispatch_request() File "/home/kn/PyProjects/ticker-api/.venv/lib/python3.10/site-packages/flask/app.py", line 1799, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) File "/home/kn/PyProjects/ticker-api/app.py", line 106, in ticker_employees result = yf.Ticker(symbol,proxy=local_proxy,session=session).get_major_holders().to_dict() File "/home/kn/PyProjects/ticker-api/.venv/lib/python3.10/site-packages/yfinance/base.py", line 175, in get_major_holders data = self._holders.major File "/home/kn/PyProjects/ticker-api/.venv/lib/python3.10/site-packages/yfinance/scrapers/holders.py", line 35, in major self._fetch_and_parse() File "/home/kn/PyProjects/ticker-api/.venv/lib/python3.10/site-packages/yfinance/scrapers/holders.py", line 107, in _fetch_and_parse raise YFinanceDataException("Failed to parse holders json data.") yfinance.exceptions.YFinanceDataException: Failed to parse holders json data.

Bad data proof

No response

yfinance version

0.2.37

Python version

No response

Operating system

No response

ismoo1 commented 8 months ago

I have the same issue, I iterated these elements in bold failing But I noted this only with SPOTify, many other tickers OK like 'MA', 'PFE', 'META', 'INTC', 'MSFT', 'NFLX' could it by some kind of random rate limiter in yfinance? ticker = yf.Ticker('SPOT')

Get all available data elements

data_elements = { "info": ticker.info, "history": ticker.history(period="1y"), "history_metadata": ticker.history_metadata, "actions": ticker.actions, "dividends": ticker.dividends, "splits": ticker.splits, "capital_gains": ticker.capital_gains, "shares_full": ticker.get_shares_full(start="2022-01-01", end=None), "income_stmt": ticker.income_stmt, "quarterly_income_stmt": ticker.quarterly_income_stmt, "balance_sheet": ticker.balance_sheet, "quarterly_balance_sheet": ticker.quarterly_balance_sheet, "cashflow": ticker.cashflow, "quarterly_cashflow": ticker.quarterly_cashflow, "major_holders": ticker.major_holders, "institutional_holders": ticker.institutional_holders, "mutualfund_holders": ticker.mutualfund_holders, "insider_transactions": ticker.insider_transactions, "insider_purchases": ticker.insider_purchases, "insider_roster_holders": ticker.insider_roster_holders, "recommendations": ticker.recommendations, "recommendations_summary": ticker.recommendations_summary, "upgrades_downgrades": ticker.upgrades_downgrades, "earnings_dates": ticker.earnings_dates, "news": ticker.news }

michaelmoopenn commented 5 months ago

Got same issue on my side with ticker ING.