Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_income_statement: string indices must be integers #94

Open
garroshub opened this issue Dec 17, 2022 · 9 comments
Open

get_income_statement: string indices must be integers #94

garroshub opened this issue Dec 17, 2022 · 9 comments

Comments

@garroshub
Copy link

Under Stock_info:

image

Can not get data, I checked line by line, and when running json_info["incomeStatementHistory"]["incomeStatementHistory"], it will report must be integers.

Then I checked _parse_json function:
image
The function can not get the quotesummarystore part. It says they must be integers, and cannot use string indices to get them.

Does anyone meet a similar issue?

@dkivi
Copy link

dkivi commented Dec 18, 2022

Same issue here with for example:

aapl_earnings_hist = si.get_earnings_history("aapl")

@xyzitfinance
Copy link

Hi,

Seems that the issue is not related only to some functions.

Seems that is something in the api response that is coming from Yahoo Finance.

Let's take the following example:

  • in stock_info.py we are having the following function = get_earnings_history .

With the help of _parse_earnings_json(url)**** we retrive information from Yahoo Finance.

image

the problem: is in the api response because key = "stores" is somehow encrypted.

image

In order to figure out if is something related to yahoo_fin (expected to not be since no updates happened) I checked the information in Postman and run an GET URL API:

image

Seems that Yahoo Fin is starting to encrypt some information (maybe I;m wrong).

@garroshub
Copy link
Author

Hi,

Seems that the issue is not related only to some functions.

Seems that is something in the api response that is coming from Yahoo Finance.

Let's take the following example:

  • in stock_info.py we are having the following function = get_earnings_history .

With the help of _parse_earnings_json(url)**** we retrive information from Yahoo Finance.

image

the problem: is in the api response because key = "stores" is somehow encrypted.

image

In order to figure out if is something related to yahoo_fin (expected to not be since no updates happened) I checked the information in Postman and run an GET URL API:

image

Seems that Yahoo Fin is starting to encrypt some information (maybe I;m wrong).

If it is because Yahoo Finance encrypts some information, do you know of any user-side solutions?

@xyzitfinance
Copy link

Nope, but seems that not only yahoo_fin is having this issue.

Maybe to owner of the project is more familiar than me with the Yahoo Finance flow and with python.

@danthings
Copy link

danthings commented Dec 18, 2022

Ok, so after some research, indeed the issue is coming from the Yahoo API.

I found that also other people that are using other libraries are having the some issues.

I don t know if is fine to specify the library but somehow they succeed to fix it.

The fix relates to the fact that they are decrypting the information with some AES parser & cipher.

I m not familiar to much with python, but in their cases seems to work and I have no idea if this library is still updated or not

@garroshub
Copy link
Author

Ok, so after some research, indeed the issue is coming from the Yahoo API.

I found that also other people that are using other libraries are having the some issues.

I don t know if is fine to specify the library but somehow they succeed to fix it.

The fix relates to the fact that they are decrypting the information with some AES parser & cipher.

I m not familiar to much with python, but in their cases seems to work and I have no idea if this library is still updated or not

I am not familiar with AES parser and cypher. Perhaps you could provide the links you referenced that address similar issues.

@lrauhockey
Copy link

here is the pull request from yfinance that has fixed the encryption issue - ranaroussi/yfinance#1253

@sonso-1
Copy link

sonso-1 commented Dec 20, 2022

here is the pull request from yfinance that has fixed the encryption issue - ranaroussi/yfinance#1253

I was experiencing the issue when calling get_earnings_for_date(). Found a workaround using a snippet of the fix from yfinance.

Below is the workaround for my use case. This is not a proper fix, only posting it here for real developers to come up with a proper fix and update the yahoo_fin project. Until then, this workaround may work for others as well.

  1. Replace the stock_info.py in your python project (...\Lib\site-packages\yahoo_fin\stock_info.py) with the attached updated version
  2. Install additional python modules to handle the decryption
    import hashlib
    from base64 import b64decode
    from cryptography.hazmat.primitives import padding
    from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes

"changelog"

  • added the import statements above
  • added the function decrypt_cryptojs_aes()
  • modified get_earnings_for_date()
    changed "stores = result['context']['dispatcher']['stores']" to "stores = decrypt_cryptojs_aes(result)"'

stock_info.py.txt

@collinL33T
Copy link

Just move all your stuff to yfinance, this dev gave up on this project already. The module has not been updated in almost 2 yrs. Since the Yahoo API issue occurred last week, yfinance has already issued out 2 patches to remedy the same issue we are requesting to fix right now.

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

No branches or pull requests

7 participants