[0.2.61]"error":{"code":"Unauthorized","description":"Invalid Cookie"}
Describe bug
newly installed 0.2.61 has below "error":{"code":"Unauthorized","description":"Invalid Cookie"} while 0.2.60 not
Simple code that reproduces your problem
import yfinance as yf
yf.enable_debug_mode() dat = yf.Ticker("AAPL") print(dat.info)
Debug log from yf.enable_debug_mode()
DEBUG get_raw_json(): https://query2.finance.yahoo.com/v10/finance/quoteSummary/AAPL DEBUG Entering get() DEBUG Entering _make_request() DEBUG url=https://query2.finance.yahoo.com/v10/finance/quoteSummary/AAPL DEBUG params={'modules': 'financialData,quoteType,defaultKeyStatistics,assetProfile,summaryDetail', 'corsDomain': 'finance.yahoo.com', 'formatted': 'false', 'symbol': 'AAPL'} DEBUG Entering _get_cookie_and_crumb() DEBUG cookie_mode = 'basic' DEBUG Entering _get_cookie_and_crumb_basic() DEBUG Entering _get_cookie_basic() DEBUG Entering _load_cookie_curlCffi() DEBUG Exiting _load_cookie_curlCffi() DEBUG reusing persistent cookie DEBUG Exiting _get_cookie_basic() DEBUG Entering _get_crumb_basic() DEBUG Entering _get_cookie_basic() DEBUG reusing cookie DEBUG Exiting _get_cookie_basic() DEBUG crumb = 'qBH7aJzknFw' DEBUG Exiting _get_crumb_basic() DEBUG Exiting _get_cookie_and_crumb_basic() DEBUG Exiting _get_cookie_and_crumb() DEBUG response code=401 DEBUG toggling cookie strategy basic -> csrf DEBUG Entering _get_cookie_and_crumb() DEBUG cookie_mode = 'csrf' DEBUG Entering _get_crumb_csrf() DEBUG Entering _get_cookie_csrf() DEBUG Entering _load_cookie_curlCffi() DEBUG Exiting _load_cookie_curlCffi() DEBUG reusing persistent cookie DEBUG Exiting _get_cookie_csrf() DEBUG crumb = '{"finance":{"result":null,"error":{"code":"Unauthorized","description":"Invalid Cookie"}}}' DEBUG Exiting _get_crumb_csrf() DEBUG Exiting _get_cookie_and_crumb() DEBUG response code=401 DEBUG Exiting _make_request() DEBUG Exiting get()
Bad data proof
No response
yfinance version
0.2.61
Python version
3.12
Operating system
macosx 15.3.1
0.2.61 didn't change anything in data.py.
0.2.60 restored cookie reuse:
DEBUG reusing persistent cookie
Curious what makes cookie invalid
I am having the same error
Need to see the cookie. Someone print their cookies or upload cookies.db https://ranaroussi.github.io/yfinance/advanced/caching.html
Thank you for the information about the cookies-db. I have attached the file from the last unsuccessful program run. This returns None: stock_info = stock.history(start=last_update_date, end=datetime.today().date(), actions=True, auto_adjust=False, repair=False)
What I have noticed, however: The cookies.db-wal is not empty, but contains 97 KB of data. Doesn't this indicate an open transaction?
@Hektiker24 I tried your cookie, works fine. Compare your debug log to mine:
debug log
DEBUG Entering history()
DEBUG Entering _fetch_ticker_tz()
DEBUG Entering get()
DEBUG Entering _make_request()
DEBUG url=https://query2.finance.yahoo.com/v8/finance/chart/INTC
DEBUG params=frozendict.frozendict({'range': '1d', 'interval': '1d'})
DEBUG Entering _get_cookie_and_crumb()
DEBUG cookie_mode = 'basic'
DEBUG Entering _get_cookie_and_crumb_basic()
DEBUG Entering _get_cookie_basic()
DEBUG Entering _load_cookie_curlCffi()
DEBUG Exiting _load_cookie_curlCffi()
DEBUG Entering _save_cookie_curlCffi()
DEBUG Exiting _save_cookie_curlCffi()
DEBUG Exiting _get_cookie_basic()
DEBUG Entering _get_crumb_basic()
DEBUG Entering _get_cookie_basic()
DEBUG Entering _load_cookie_curlCffi()
DEBUG Exiting _load_cookie_curlCffi()
DEBUG reusing persistent cookie
DEBUG Exiting _get_cookie_basic()
DEBUG crumb = 'xJ1jfJlQjcg'
DEBUG Exiting _get_crumb_basic()
DEBUG Exiting _get_cookie_and_crumb_basic()
DEBUG Exiting _get_cookie_and_crumb()
DEBUG response code=200
Elaborate on "I have attached the file from the last unsuccessful program run." - did you actually get error "Invalid Cookie"?
Yes, it seem's it works fine. I was confused by the error message "Too many users" and thought it was coming from Yahoo. Only after your hint about the cookies.db did I see that the WAL file contains data, which indicates an unfinished transaction. In the script that also uses yfinance, transaction control was implemented because multiple write operations to the database are required. The root cause of the error comes from SQLite. It seems that multiple transactions with SQLite are not possible, even if they are transactions on different database files. That's quite strange. So, one of us should probably avoid using transactions.😊 I think that SQLite is no longer sufficient for the growing requirements and I am looking for a more suitable solution. Thanks for your support.