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_key_statistics_data() http 401 yahoofinancials version 1.19 #170

Closed bjosun closed 6 months ago

bjosun commented 6 months ago

Downloaded the latest version 1.19 first it did work, but now it gets the 401

from yahoofinancials import YahooFinancials yahoo_financials = YahooFinancials('MSFT') yahoo_financials.get_key_statistics_data() Traceback (most recent call last): File "", line 1, in File "/Users/bj/cv-venv/lib/python3.8/site-packages/yahoofinancials/yf.py", line 106, in get_key_statistics_data return self.get_clean_data(self.get_stock_tech_data('defaultKeyStatistics'), 'defaultKeyStatistics') File "/Users/bj/cv-venv/lib/python3.8/site-packages/yahoofinancials/etl.py", line 617, in get_stock_tech_data return self.get_stock_data(statement_type='keystats', tech_type=tech_type) File "/Users/bj/cv-venv/lib/python3.8/site-packages/yahoofinancials/etl.py", line 589, in get_stock_data dict_ent = self._create_dict_ent(self.ticker, statement_type, tech_type, report_name, hist_obj) File "/Users/bj/cv-venv/lib/python3.8/site-packages/yahoofinancials/etl.py", line 541, in _create_dict_ent re_data = self._get_historical_data(YAHOO_URL, r_map, tech_type, statement_type) File "/Users/bj/cv-venv/lib/python3.8/site-packages/yahoofinancials/etl.py", line 268, in _get_historical_data self._request_handler(url, config.get("response_field")) File "/Users/bj/cv-venv/lib/python3.8/site-packages/yahoofinancials/etl.py", line 229, in _request_handler raise ManagedException("Server replied with server error code, HTTP " + str(response.status_code) + yahoofinancials.etl.ManagedException: Server replied with server error code, HTTP 401 code while opening the url: https://query1.finance.yahoo.com/v10/finance/quoteSummary/msft?modules=defaultKeyStatistics&formatted=False&lang=en-US&region=US&corsDomain=finance.yahoo.com

Could it be a crumb issue still?

bjosun commented 6 months ago

played around with while i < 150: try: db.connect() Cookie_db_proxy.initialize(db) db.create_tables([_CookieSchema]) self.initialised = 1 # success return except _peewee.OperationalError: time.sleep(random.randint(3, 10))

extended the while loop and the sleep now it gets the crumb :)

JECSand commented 6 months ago

@bjosun Nice! Would you mind opening a PR with those changes? I suspect it may benefit others as well.