I am running some simple test code for yfinance on two machines; both machines are running the same version of yahoo finance (0.2.33), one is on Windows 8.1 and one is on Fedora linux. Both are running the same version of python 3.9.7 with the same VSCode environment. The code runs with no problem on the Windows machine but throws errors even for simple test cases such as trying to get the .info of a ticker. I have not been able to identify why this is; the only tangible difference in environment is that the Fedora machine is running the code on a venv to manage dependencies more carefully.
Simple code that reproduces your problem
from datetime import datetime
import yfinance as yf
def new_lows(t: str, offset: int) -> list:
current_year = datetime.now().year
hist_raw = yf.Ticker(t).history(start=f"{current_year - offset}-01-01", end=f"{current_year - offset}-12-31", interval="1d").reset_index()
if hist_raw.empty: # If period is before company founding date
return [[None,None], None]
hist_raw['Date'] = hist_raw['Date'].dt.strftime('%Y-%m-%d')
hist = hist_raw.to_dict("list")["Close"]
low = hist[0]
new_lows = 0
for v in hist[1:]:
if v < low:
new_lows += 1
low = v
return new_lows
new_lows("AAPL", 2)
The above code should output "22"; on Fedora the history fetch will come up empty and print the following:
AAPL: No price data found, symbol may be delisted (1d 2022-01-01 -> 2022-12-31)
t = yf.Ticker("AAPL")
t.info
The above code should output the relevant company information for AAPL. However on Fedora it will give a TypeError:
TypeError: unsupported operand type(s) for -: 'datetime.datetime' and 'str'
Describe bug
I am running some simple test code for yfinance on two machines; both machines are running the same version of yahoo finance (0.2.33), one is on Windows 8.1 and one is on Fedora linux. Both are running the same version of python 3.9.7 with the same VSCode environment. The code runs with no problem on the Windows machine but throws errors even for simple test cases such as trying to get the
.info
of a ticker. I have not been able to identify why this is; the only tangible difference in environment is that the Fedora machine is running the code on a venv to manage dependencies more carefully.Simple code that reproduces your problem
The above code should output "22"; on Fedora the history fetch will come up empty and print the following:
The above code should output the relevant company information for AAPL. However on Fedora it will give a TypeError:
Debug log
For code
print(t.info)
:DEBUG get_raw_json(): https://query2.finance.yahoo.com/v10/finance/quoteSummary/AAPL DEBUG Entering get() DEBUG url=https://query2.finance.yahoo.com/v10/finance/quoteSummary/AAPL DEBUG params={'modules': 'financialData,quoteType,defaultKeyStatistics,assetProfile,summaryDetail', 'ssl': 'true'} DEBUG Entering _get_cookie_and_crumb() DEBUG cookie_mode = 'basic' DEBUG Entering _get_cookie_and_crumb_basic()
Full traceback:
For
new_lows
code: DEBUG Entering history() DEBUG AAPL: Yahoo GET parameters: {'period1': '2022-01-01 00:00:00-05:00', 'period2': '2022-12-31 00:00:00-05:00', 'interval': '1d', 'includePrePost': False, 'events': 'div,splits,capitalGains'} DEBUG Entering get() DEBUG url=https://query2.finance.yahoo.com/v8/finance/chart/AAPL DEBUG params=frozendict.frozendict({'period1': 1641013200, 'period2': 1672462800, 'interval': '1d', 'includePrePost': False, 'events': 'div,splits,capitalGains'}) DEBUG Entering _get_cookie_and_crumb() DEBUG cookie_mode = 'basic' DEBUG Entering _get_cookie_and_crumb_basic() ERROR AAPL: No price data found, symbol may be delisted (1d 2022-01-01 -> 2022-12-31) DEBUG Exiting history()Bad data proof
No response
yfinance
version0.2.33
Python version
3.9.7
Operating system
Fedora LXDE Linux