yfinance: KeyError: 'exchangeTimezoneName' when accessing ticker history
Current yfinance 0.1.75 raises an exception when running the following:
import yfinance as yf
def _main():
stock_data = yf.download(
"AFN",
start="2018-01-01",
end="2018-12-31",
group_by="ticker",
threads=False
)
print(stock_data)
if __name__ == "__main__":
_main()
stock_data = yf.download(
File "/Users/manoel/opt/anaconda3/envs/Qiskitenv/lib/python3.8/site-packages/yfinance/multi.py", line 120, in download
data = _download_one(ticker, period=period, interval=interval,
File "/Users/manoel/opt/anaconda3/envs/Qiskitenv/lib/python3.8/site-packages/yfinance/multi.py", line 205, in _download_one
return Ticker(ticker).history(period=period, interval=interval,
File "/Users/manoel/opt/anaconda3/envs/Qiskitenv/lib/python3.8/site-packages/yfinance/base.py", line 148, in history
end = utils._parse_user_dt(end, self._get_ticker_tz())
File "/Users/manoel/opt/anaconda3/envs/Qiskitenv/lib/python3.8/site-packages/yfinance/base.py", line 328, in _get_ticker_tz
tkr_tz = self.info["exchangeTimezoneName"]
KeyError: 'exchangeTimezoneName'
Running the same sample against the previous release returns:
[*********************100%***********************] 1 of 1 completed
Open High Low Close Adj Close Volume
Date
2018-01-02 29.799999 29.799999 29.799999 29.799999 29.799999 0
2018-01-03 30.000000 30.000000 30.000000 30.000000 30.000000 0
2018-01-04 30.000000 30.000000 30.000000 30.000000 30.000000 0
2018-01-05 30.200001 30.200001 30.200001 30.200001 30.200001 0
2018-01-08 30.000000 30.000000 30.000000 30.000000 30.000000 0
2018-01-09 30.200001 30.200001 30.200001 30.200001 30.200001 0
2018-01-10 32.799999 32.799999 32.799999 32.799999 32.799999 0
2018-01-11 31.799999 31.799999 31.799999 31.799999 31.799999 0
2018-01-12 30.799999 30.799999 30.799999 30.799999 30.799999 0
2018-01-16 30.200001 30.200001 30.200001 30.200001 30.200001 0
2018-01-17 30.799999 30.799999 30.799999 30.799999 30.799999 0
2018-01-18 30.799999 30.799999 30.799999 30.799999 30.799999 0
2018-01-19 30.799999 30.799999 30.799999 30.799999 30.799999 0
2018-01-22 31.400000 31.400000 31.400000 31.400000 31.400000 0
2018-01-23 32.000000 32.000000 32.000000 32.000000 32.000000 0
2018-01-24 31.600000 31.600000 31.600000 31.600000 31.600000 0
2018-01-25 31.200001 31.200001 31.200001 31.200001 31.200001 0
2018-01-26 32.200001 32.200001 32.200001 32.200001 32.200001 0
2018-01-29 31.799999 31.799999 31.799999 31.799999 31.799999 0
2018-01-30 31.520000 31.520000 31.520000 31.520000 31.520000 0
If I run with threads=True
it will raise the exception and hang.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 21 (8 by maintainers)
Commits related to this issue
- Small cleanup to ease finding bug #1076. Begun by getting rid of multiple calls to self.info (get_info). — committed to fredrik-corneliusson/yfinance-tz-cache by fredrik-corneliusson 2 years ago
- Merge pull request #1109 from fredrik-corneliusson/dev Fix for #1076 — committed to ranaroussi/yfinance by ValueRaider 2 years ago
That’s a good point, it should print a nice message. Will fix for next release.
Good point. I’ll push an update to
dev