Skip to content

Conversation

@Featuredutka
Copy link

@Featuredutka Featuredutka commented Feb 12, 2022

Fix for the issue

#511

After a couple of experiments I found out that the error was caused by python trying to convert an empty string to the float.

Sample terminal output for 'PG' stock:

0.41
0.41
0.41

Traceback (most recent call last):
  File "/Users/ash/Desktop/stonks/ui.py", line 107, in run
    main.main(self.progresslink)
  File "/Users/ash/Desktop/stonks/main.py", line 51, in main
    stock_info = investpy.stocks.get_stock_dividends(stock, country=country_data[countryiterator])
  File "/Users/ash/opt/anaconda3/lib/python3.9/site-packages/investpy/stocks.py", line 973, in get_stock_dividends
    dividend_value = float(element_.getnext().text_content())
ValueError: could not convert string to float: ''
Abort trap: 6

So, apparantely that blank line was causing all the problems, but not any more with the try/except wrap.

@Featuredutka
Copy link
Author

Featuredutka commented Feb 12, 2022

Some checks later I discovered that the problem is not completely gone. It appears there are some stocks with no provided information at all (like PFE or MRK on the screenshot) - not even an empty string. So the try/exception wrap won't work for those.

Console data output for each stock in list:
Screen Shot 2022-02-13 at 01 43 36

To fix that another try/except clause was added

Console output after fix:
Screen Shot 2022-02-13 at 02 04 17

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

Successfully merging this pull request may close these issues.

1 participant