yfinance icon indicating copy to clipboard operation
yfinance copied to clipboard

fast_info returning error on non available quotes

Open uzala92 opened this issue 8 months ago • 0 comments

Describe bug

I have seen that fast info when passed a ticker that is not currently available, an error occurs due to the reading of non-existing parameters, in this case, currency.

Simple code that reproduces your problem

import yfinance as yf

stock = yf.Ticker("FDQ.BE")

stock.get_fast_info() # same with stock.fast_info

Debug log

Traceback (most recent call last): File "/home/user/code/src/functions.py", line 11, in get_info_data fast_info = stock.get_fast_info() File "/home/user/code/venv/lib/python3.10/site-packages/yfinance/scrapers/quote.py", line 165, in getitem return getattr(self, k) File "/home/user/code/venv/lib/python3.10/site-packages/yfinance/scrapers/quote.py", line 255, in currency self._currency = md["currency"] KeyError: 'currency'

Bad data proof

I think it could be easily solved by doing .get() of the dictionary. Knowing that all the response parameters have a default value of None, the get() would make them keep the None value and return a dictionary with those parameters to None as the user expects instead of throwing an error.

yfinance version

0.2.40

Python version

3.10.12

Operating system

Ubuntu 22.04

uzala92 avatar May 29 '24 06:05 uzala92