ranaroussi / yfinance

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

_get_decryption_keys_from_yahoo_js(soup) got yfinance failed to decrypt Yahoo data response error #1425

Closed seohyunjun closed 1 year ago

seohyunjun commented 1 year ago

IMPORTANT

Confirm by running: tf version : 0.2.12 python version : 3.9.7 using ticker: "AAPL"

Thank you update quickely 0.2.11 -> 0.2.12

but i found error " " in scraper.py tk = TickerData("AAPL") tk._get_decryption_keys_from_yahoo_js(soup)

from yfinance.data import decrypt_cryptojs_aes_stores, TickerData

headers = {
  'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36'
  }
url = 'https://finance.yahoo.com/calendar/earnings'
response = requests.get(url, headers=headers)
page_content = response.content.decode(encoding='utf-8',errors='strict')
soup = BeautifulSoup(response.content, "html.parser")

td = TickerData("AAPL")
keys = td._get_decryption_keys_from_yahoo_js(soup)
page_data_string = [row for row in page_content.split(
  '\n') if row.startswith('root.App.main = ')][0][:-1]
page_data_string = page_data_string.split('root.App.main = ', 1)[1]
decrypt_cryptojs_aes_stores(json.loads(page_data_string),keys) # yfinance failed to decrypt Yahoo data response
print(keys) # []

im using yfinance with https://github.com/wenboyu2/yahoo-earnings-calendar/pull/35

Thank you share good repo

ValueRaider commented 1 year ago
keys = td._get_decryption_keys_from_yahoo_js(soup)

_get_decryption_keys_from_yahoo_js stopped working 10 days ago, yfinance uses other "backup" methods now. Stick to the documented API - yfinance.Ticker etc.

seohyunjun commented 1 year ago

It seems like my coding skills are not sufficient to understand it properly, so I will refer to the Yahoo Finance API. Thank you for answering my question!!"