JECSand / yahoofinancials

A powerful financial data module used for pulling data from Yahoo Finance. This module can pull fundamental and technical data for stocks, indexes, currencies, cryptos, ETFs, Mutual Funds, U.S. Treasuries, and commodity futures.
https://pypi.python.org/pypi/yahoofinancials
MIT License
896 stars 214 forks source link

get_stock_earnings_data always fails #164

Closed ian-hailey closed 6 months ago

ian-hailey commented 7 months ago

I get the following error when attempting to call many of the methods such as get_stock_earnings_data.

Calls to get_financial_stmts, get_financial_stmts and get_historical_price_data are always working.

Any ideas what could be the issue?

This test was with v1.17 on a MAC with python 3.9.

apple_earnings_data = yahoo_financials.get_stock_earnings_data()

Traceback (most recent call last): File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/_pydevd_bundle/pydevd_exec2.py", line 3, in Exec exec(exp, global_vars, local_vars) File "", line 1, in File "/Library/Python/3.9/site-packages/yahoofinancials-1.17-py3.9.egg/yahoofinancials/yf.py", line 121, in get_stock_earnings_data return self.get_stock_tech_data('earnings') File "/Library/Python/3.9/site-packages/yahoofinancials-1.17-py3.9.egg/yahoofinancials/etl.py", line 595, in get_stock_tech_data return self.get_stock_data(tech_type=tech_type) File "/Library/Python/3.9/site-packages/yahoofinancials-1.17-py3.9.egg/yahoofinancials/etl.py", line 565, in get_stock_data dict_ent = self._create_dict_ent(self.ticker, statement_type, tech_type, report_name, hist_obj) File "/Library/Python/3.9/site-packages/yahoofinancials-1.17-py3.9.egg/yahoofinancials/etl.py", line 521, in _create_dict_ent re_data = self._get_historical_data(YAHOO_URL, r_map, tech_type, statement_type) File "/Library/Python/3.9/site-packages/yahoofinancials-1.17-py3.9.egg/yahoofinancials/etl.py", line 248, in _get_historical_data self._request_handler(url, config.get("response_field")) File "/Library/Python/3.9/site-packages/yahoofinancials-1.17-py3.9.egg/yahoofinancials/etl.py", line 190, in _request_handler cur_url += "&crumb=" + self.crumb TypeError: can only concatenate str (not "NoneType") to str

income_statement_data_qt = yahoo_financials.get_financial_stmts('quarterly', 'income') income_statement_data_qt {'incomeStatementHistoryQuarterly': {'AAPL': [{'2023-06-30': {'basicAverageShares': 15697614000.0, .....etc

bjosun commented 7 months ago

I have the same problem with get_key_statistics_data(). Tired a few of the Additional Module Methods and most of them have the same TypeError. raceback (most recent call last): File "", line 1, in File "/Users/bjosun/oe_project/github/cv-venv/lib/python3.8/site-packages/yahoofinancials/yf.py", line 121, in get_stock_earnings_data return self.get_stock_tech_data('earnings') File "/virtual/lib/python3.8/site-packages/yahoofinancials/etl.py", line 595, in get_stock_tech_data return self.get_stock_data(tech_type=tech_type) File "/virtual/lib/python3.8/site-packages/yahoofinancials/etl.py", line 570, in get_stock_data dict_ents = pool.map(partial(self._create_dict_ent, File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/multiprocessing/pool.py", line 364, in map return self._map_async(func, iterable, mapstar, chunksize).get() File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/multiprocessing/pool.py", line 768, in get raise self._value TypeError: can only concatenate str (not "NoneType") to str

marcelloexp386 commented 7 months ago

Same problem with .get_stock_quote_type_data(). Until yesterday, it worked fine. I hope it is not linked to the same issue that is impacting on some yfinance modules since October 20!

sylvandb commented 7 months ago

It's almost certainly related. This is change is working for me but I haven't tried all the things:

In session.py about line 133 find the line which has this and change from: response = session.get('https://fc.yahoo.com') to: response = session.get('https://finance.yahoo.com/')

Steelburner commented 7 months ago

Thank you sylvandb. Your fix worked for .get_current_price.

bjosun commented 7 months ago

Does not work for me get a 401 with finance.yahoo.com: yahoofinancials.etl.ManagedException: Server replied with server error code, HTTP 401 code while opening the url: https://query2.finance.yahoo.com/v10/finance/quoteSummary/v?modules=defaultKeyStatistics&formatted=False&lang=en-US&region=US&corsDomain=finance.yahoo.com&crumb=

Using get_key_statistics_data()

But with finance.yahoo.com added to response, the response of running from yahoofinancials import YahooFinancials tickers = ['AAPL', 'GOOG', 'C'] yahoo_financials = YahooFinancials(tickers, concurrent=True, max_workers=8, country="US") balance_sheet_data_qt = yahoo_financials.get_financial_stmts('quarterly', 'balance') print(balance_sheet_data_qt) Running this is way faster than with fc.yahoo.com and it works, but does not work for me when running .get_current_price and get_key_statistics_data() then i get a 401. So i guess there is some sort of authentication needed for that url.

marcelloexp386 commented 7 months ago

It seems like there are some modules where the fix suggested by sylvandb works and others where it returns the error noted also by bjosun. For example, get_current_price() and get_financial_data() don't work, whereas get_financial_stmts works.

JECSand commented 6 months ago

Hey all, taking care of this now.

JECSand commented 6 months ago

Closing this issue with release of v1.18. Thank you everyone!