investpy
investpy copied to clipboard
investpy.get_stock_dividends could not convert string to float
Hello!
I get this error for some stocks:
In [2]: import investpy
In [3]: investpy.get_stock_dividends('USB', 'united states')
ValueError Traceback (most recent call last)
/usr/local/lib/python3.7/site-packages/investpy/stocks.py in get_stock_dividends(stock, country) 1167 element_.getnext() 1168 .text_content() -> 1169 .replace(",", "") 1170 ) 1171 if element_.get("data-value") in type_values.keys():
ValueError: could not convert string to float:
In [4]: i found this error with: SO US8425871071 GIS US3703341046 MRK US58933Y1055 PFE US7170811035 MO US02209S1033 USB US9029733048 VZ US92343V1044 IP US4601461035 BEN US3546131018 CAH US14149Y1082 BMY US1101221083 HPE US42824C1099 MET US59156R1086 ALV@DE DE0008404005 FRE@DE DE0005785604 MUV2@DE DE0008430026
Hi, same problem here - I am looping through a list of stocks and getting dividents, but recently after adding a couple of new positions got that error as well:
Traceback (most recent call last):
File "/Users/ash/opt/anaconda3/lib/python3.9/site-packages/investpy/stocks.py", line 908, in get_stock_dividends
dividend_value = float(element_.getnext().text_content().replace(',', ''))
Code I am using to get dividents:
stock_info = investpy.stocks.get_stock_dividends(stock, country=country_data[countryiterator])
I managed to deal with this error by simply skipping stocks with such an error by using try/except clause like this:
except ValueError:
print(' - ', stock, ' - DATA NOT FOUND')
I will try to dive into the source code and deal with this problem :)
Added error list:
KO US PEP US O US