ranaroussi / yfinance

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

I have an error at call "msft.info" #1392

Closed SDayneko closed 1 year ago

SDayneko commented 1 year ago

~### Discussed in https://github.com/ranaroussi/yfinance/discussions/1391~ deleted by @ValueRaider

Originally posted by **SDayneko** February 1, 2023 Exception Traceback (most recent call last) Cell In[30], line 1 ----> 1 msft.info File ~/PycharmProjects/venv/lib/python3.11/site-packages/yfinance/ticker.py:138, in Ticker.info(self) 136 @property 137 def info(self) -> dict: --> 138 return self.get_info() File ~/PycharmProjects/venv/lib/python3.11/site-packages/yfinance/base.py:895, in TickerBase.get_info(self, proxy) 893 def get_info(self, proxy=None) -> dict: 894 self._quote.proxy = proxy --> 895 data = self._quote.info 896 return data File ~/PycharmProjects/venv/lib/python3.11/site-packages/yfinance/scrapers/quote.py:27, in Quote.info(self) 24 @property 25 def info(self) -> dict: 26 if self._info is None: ---> 27 self._scrape(self.proxy) 28 self._scrape_complementary(self.proxy) 30 return self._info File ~/PycharmProjects/venv/lib/python3.11/site-packages/yfinance/scrapers/quote.py:56, in Quote._scrape(self, proxy) 53 self._already_scraped = True 55 # get info and sustainability ---> 56 json_data = self._data.get_json_data_stores(proxy=proxy) 57 try: 58 quote_summary_store = json_data['QuoteSummaryStore'] File ~/PycharmProjects/venv/lib/python3.11/site-packages/yfinance/data.py:40, in lru_cache_freezeargs..wrapped(*args, **kwargs) 38 args = tuple([tuple(arg) if isinstance(arg, list) else arg for arg in args]) 39 kwargs = {k: tuple(v) if isinstance(v, list) else v for k, v in kwargs.items()} ---> 40 return func(*args, **kwargs) File ~/PycharmProjects/venv/lib/python3.11/site-packages/yfinance/data.py:202, in TickerData.get_json_data_stores(self, sub_page, proxy) 198 return {} 200 data = json.loads(json_str) --> 202 stores = decrypt_cryptojs_aes_stores(data) 203 if stores is None: 204 # Maybe Yahoo returned old format, not encrypted 205 if "context" in data and "dispatcher" in data["context"]: File ~/PycharmProjects/venv/lib/python3.11/site-packages/yfinance/data.py:73, in decrypt_cryptojs_aes_stores(data) 71 for i in range(1, len(new_keys)): 72 msg += f" , '{k_str}'->{type(data[k])}" ---> 73 raise Exception(msg) 74 password_key = new_keys[0] 75 password = data[password_key] Exception: Yahoo has again changed data format, yfinance now unsure which key(s) is for decryption: 'f8573b84c0ef'-> , 'f8573b84c0ef'-> , 'f8573b84c0ef'-> , 'f8573b84c0ef'-> , 'f8573b84c0ef'-> , 'f8573b84c0ef'-> , 'f8573b84c0ef'-> , 'f8573b84c0ef'-> , 'f8573b84c0ef'-> , 'f8573b84c0ef'-> , 'f8573b84c0ef'-> , 'f8573b84c0ef'-> , 'f8573b84c0ef'-> , 'f8573b84c0ef'-> , 'f8573b84c0ef'-> , 'f8573b84c0ef'-> , 'f8573b84c0ef'-> , 'f8573b84c0ef'-> , 'f8573b84c0ef'-> , 'f8573b84c0ef'-> , 'f8573b84c0ef'-> , 'f8573b84c0ef'-> , 'f8573b84c0ef'-> ,
SDayneko commented 1 year ago

Also, I had the same problem at run the next code: import yfinance as yf

ticker = yf.Ticker("AAPL") price = ticker.history(period="1d").iloc[-1]["Close"] balance_sheet = ticker.balance_sheet(period="quarter").iloc[-1] shares = balance_sheet["Shares Outstanding"] market_cap = price * shares print("Market capitalization:", market_cap)

error: Exception: Yahoo has again changed data format, yfinance now unsure which key(s) is for decryption.

pineapplentrees commented 1 year ago

You should read error logs! this is the error

Exception: Yahoo has again changed data format, yfinance now unsure which key(s) is for decryption:

ValueRaider commented 1 year ago

@SDayneko Read the Issue default message! You didn't confirm running latest version.