Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ticker.info returning value for non existing tickers #1905

Open
subhammoda opened this issue Apr 12, 2024 · 1 comment
Open

ticker.info returning value for non existing tickers #1905

subhammoda opened this issue Apr 12, 2024 · 1 comment

Comments

@subhammoda
Copy link

Describe bug

The following code used to work fine previously while trying to check if a ticker exists as the info would return 404 error, but not info returns 'trailingPegRatio' value even for non-existing tickers.

Simple code that reproduces your problem

import yfinance as yf

yf.enable_debug_mode()

symbol = "FAKE"
ticker = yf.Ticker(symbol)
info = None

try:
  info = ticker.info
except:
  print("Ticker {} probably does not exist.".format(symbol))
else:  
  print("Info of {}:{}".format(symbol, info))

Debug log

DEBUG get_raw_json(): https://query2.finance.yahoo.com/v10/finance/quoteSummary/FAKE
DEBUG Entering get()
DEBUG url=https://query2.finance.yahoo.com/v10/finance/quoteSummary/FAKE
DEBUG params={'modules': 'financialData,quoteType,defaultKeyStatistics,assetProfile,summaryDetail', 'corsDomain': 'finance.yahoo.com', 'formatted': 'false', 'symbol': 'FAKE'}
DEBUG Entering _get_cookie_and_crumb()
DEBUG cookie_mode = 'basic'
DEBUG Entering _get_cookie_and_crumb_basic()
DEBUG loaded persistent cookie
DEBUG reusing cookie
DEBUG crumb = 'SYvgBDKYViL'
DEBUG Exiting _get_cookie_and_crumb_basic()
DEBUG Exiting _get_cookie_and_crumb()
DEBUG response code=404
DEBUG toggling cookie strategy basic -> csrf
DEBUG Entering _get_cookie_and_crumb()
DEBUG cookie_mode = 'csrf'
DEBUG Entering _get_crumb_csrf()
DEBUG Failed to find "csrfToken" in response
DEBUG Exiting _get_crumb_csrf()
DEBUG toggling cookie strategy csrf -> basic
DEBUG Entering _get_cookie_and_crumb_basic()
DEBUG loaded persistent cookie
DEBUG reusing cookie
DEBUG crumb = 'SYvgBDKYViL'
DEBUG Exiting _get_cookie_and_crumb_basic()
DEBUG Exiting _get_cookie_and_crumb()
DEBUG response code=404
DEBUG Exiting get()
ERROR 404 Client Error: Not Found for url: https://query2.finance.yahoo.com/v10/finance/quoteSummary/FAKE?modules=financialData%2CquoteType%2CdefaultKeyStatistics%2CassetProfile%2CsummaryDetail&corsDomain=finance.yahoo.com&formatted=false&symbol=FAKE&crumb=SYvgBDKYViL
DEBUG Entering get()
DEBUG url=https://query1.finance.yahoo.com/ws/fundamentals-timeseries/v1/finance/timeseries/FAKE?symbol=FAKE&type=trailingPegRatio&period1=1697155200&period2=1712966400
DEBUG params=None
DEBUG Entering _get_cookie_and_crumb()
DEBUG cookie_mode = 'basic'
DEBUG Entering _get_cookie_and_crumb_basic()
DEBUG reusing cookie
DEBUG reusing crumb
DEBUG Exiting _get_cookie_and_crumb_basic()
DEBUG Exiting _get_cookie_and_crumb()
DEBUG response code=200
DEBUG Exiting get()
Traceback (most recent call last):
File "/Users/subhammoda/Documents/Projects/FE520_Project/test.py", line 14, in
print(f"Info of {t}: {info}")
NameError: name 't' is not defined
subhammoda@Subhams-Air Projects % /usr/local/bin/python /Users/subhammoda/Documents/Projects/FE520_Project/test.py
DEBUG get_raw_json(): https://query2.finance.yahoo.com/v10/finance/quoteSummary/FAKE
DEBUG Entering get()
DEBUG url=https://query2.finance.yahoo.com/v10/finance/quoteSummary/FAKE
DEBUG params={'modules': 'financialData,quoteType,defaultKeyStatistics,assetProfile,summaryDetail', 'corsDomain': 'finance.yahoo.com', 'formatted': 'false', 'symbol': 'FAKE'}
DEBUG Entering _get_cookie_and_crumb()
DEBUG cookie_mode = 'basic'
DEBUG Entering _get_cookie_and_crumb_basic()
DEBUG loaded persistent cookie
DEBUG reusing cookie
DEBUG crumb = 'SYvgBDKYViL'
DEBUG Exiting _get_cookie_and_crumb_basic()
DEBUG Exiting _get_cookie_and_crumb()
DEBUG response code=404
DEBUG toggling cookie strategy basic -> csrf
DEBUG Entering _get_cookie_and_crumb()
DEBUG cookie_mode = 'csrf'
DEBUG Entering _get_crumb_csrf()
DEBUG Failed to find "csrfToken" in response
DEBUG Exiting _get_crumb_csrf()
DEBUG toggling cookie strategy csrf -> basic
DEBUG Entering _get_cookie_and_crumb_basic()
DEBUG loaded persistent cookie
DEBUG reusing cookie
DEBUG crumb = 'SYvgBDKYViL'
DEBUG Exiting _get_cookie_and_crumb_basic()
DEBUG Exiting _get_cookie_and_crumb()
DEBUG response code=404
DEBUG Exiting get()
ERROR 404 Client Error: Not Found for url: https://query2.finance.yahoo.com/v10/finance/quoteSummary/FAKE?modules=financialData%2CquoteType%2CdefaultKeyStatistics%2CassetProfile%2CsummaryDetail&corsDomain=finance.yahoo.com&formatted=false&symbol=FAKE&crumb=SYvgBDKYViL
DEBUG Entering get()
DEBUG url=https://query1.finance.yahoo.com/ws/fundamentals-timeseries/v1/finance/timeseries/FAKE?symbol=FAKE&type=trailingPegRatio&period1=1697155200&period2=1712966400
DEBUG params=None
DEBUG Entering _get_cookie_and_crumb()
DEBUG cookie_mode = 'basic'
DEBUG Entering _get_cookie_and_crumb_basic()
DEBUG reusing cookie
DEBUG reusing crumb
DEBUG Exiting _get_cookie_and_crumb_basic()
DEBUG Exiting _get_cookie_and_crumb()
DEBUG response code=200
DEBUG Exiting get()
Info of FAKE:{'trailingPegRatio': None}

Bad data proof

ticker.info should return response 404, and not {'trailingPegRatio': None}

yfinance version

0.2.37

Python version

3.9.12

Operating system

macOS

@subhammoda subhammoda changed the title Info returning value for non existing tickers ticker.info returning value for non existing tickers Apr 12, 2024
@ValueRaider
Copy link
Collaborator

#1774 is only relevant recent change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants