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

yahoo_financials.get_key_statistics_data() TypeError: string indices must be integers #105

Closed
githubkingchamp opened this issue Dec 17, 2022 · 16 comments

Comments

@githubkingchamp
Copy link

yahoo_financials.get_key_statistics_data(), Suddenly started throwing error: TypeError: string indices must be integers. Not sure anybody using this python module experiencing the error.

`from yahoofinancials import YahooFinancials

ticker = 'AAPL'
yahoo_financials = YahooFinancials(ticker)

conentKeys = yahoo_financials.get_key_statistics_data()

Traceback (most recent call last):

File "/Users/raj/opt/miniconda3/lib/python3.8/runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/Users/raj/opt/miniconda3/lib/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/Users/raj/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher/../../debugpy/main.py", line 39, in
cli.main()
File "/Users/raj/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 430, in main
run()
File "/Users/raj/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 284, in run_file
runpy.run_path(target, run_name="main")
File "/Users/raj/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 321, in run_path
return _run_module_code(code, init_globals, run_name,
File "/Users/raj/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 135, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "/Users/raj/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 124, in _run_code
exec(code, run_globals)
File "/Users/raj/Code/Machine_Learning/wb-starter/scrap_yahoo_finance3.py", line 7, in
conentKeys = yahoo_financials.get_key_statistics_data()
File "/Users/raj/opt/miniconda3/lib/python3.8/site-packages/yahoofinancials/init.py", line 613, in get_key_statistics_data
return self.get_clean_data(self.get_stock_tech_data('defaultKeyStatistics'), 'defaultKeyStatistics')
File "/Users/raj/opt/miniconda3/lib/python3.8/site-packages/yahoofinancials/init.py", line 492, in get_stock_tech_data
return self.get_stock_data(statement_type='keystats', tech_type=tech_type)
File "/Users/raj/opt/miniconda3/lib/python3.8/site-packages/yahoofinancials/init.py", line 476, in get_stock_data
dict_ent = self._create_dict_ent(self.ticker, statement_type, tech_type, report_name, hist_obj)
File "/Users/raj/opt/miniconda3/lib/python3.8/site-packages/yahoofinancials/init.py", line 409, in _create_dict_ent
re_data = self._scrape_data(YAHOO_URL, tech_type, statement_type)
File "/Users/raj/opt/miniconda3/lib/python3.8/site-packages/yahoofinancials/init.py", line 169, in _scrape_data
stores = data["context"]["dispatcher"]["stores"]["QuoteSummaryStore"][tech_type]
TypeError: string indices must be integers
`

@chingybrooks
Copy link

I have the same problems "TypeError: string indices must be integers"

@chingybrooks
Copy link

54.70.249.11 - IP Info - Yahoo Finance on Amazon AWS.
is not responding

yahoo

@Luke7389
Copy link

same issue with getting last value, however the website appears up and running, @chingybrooks what do you mean with your comment?

@divyankm
Copy link

+1

@chingybrooks
Copy link

same issue with getting last value, however the website appears up and running, @chingybrooks what do you mean with your comment?

I thought the reason is that the API is not available

@lrauhockey
Copy link

I think the data is coming back encoded and or encrypted. Beyond my capabilities to fix, but looks that way.

@sedwards2000
Copy link
Contributor

I have created a pull request with the fix hopefully it will be accepted too. I found the fix on a separate package: ranaroussi/yfinance@8e5f098

@promexio
Copy link

Yes, same issue on my side.

@RobinMoRi
Copy link

I also get the same issue using yahoo_financials.get_current_price() method. Any update on this issue?

@ton77v
Copy link

ton77v commented Dec 23, 2022

I also get the same issue using yahoo_financials.get_current_price() method. Any update on this issue?

check the answer from sedwards2000 updating the file worked for me. But make sure you also have crypto module installed
pip3 install pycryptodome

@Usbasuthkar
Copy link

Hey, I am new to GitHub and I faced the same issue and now here is the fix but I don't know what to do with the code given, like should I execute it or what am I suppose to do

@ton77v
Copy link

ton77v commented Dec 25, 2022

Hey, I am new to GitHub and I faced the same issue and now here is the fix but I don't know what to do with the code given, like should I execute it or what am I suppose to do

Hi!

You have to change the source code yourself applying the changes highlighted in the pull request. 62119be

You have to modify yahoofinancials module’s __init__.py file; there are two ways to find it:

  • use your IDE "Find in Files / Scope" (or smth like that) function searching for the original code, for example "track the last get timestamp to add a minimum delay between gets - be nice!"
  • or go to the virtual environment folder and follow the path like: lib > site-packages > yahoofinancials > __init__.py

Apply the changes and that's it! Just make sure you have "pycryptodome" module installed

@divyankm
Copy link

One easy way to install working yahoo financials library is to install library from merge request 62119be, until @JECSand Accept this merge request to master repository fixed encryption of incoming stock data #106.

Thanks @sedwards2000

Code:

!pip install -U git+https://github.com/sedwards2000/yahoofinancials@encryptionDataFix
!pip install pycryptodome
from yahoofinancials import YahooFinancials 
yahoo_financials = YahooFinancials('AAPL') 
print("Apple current price in $",yahoo_financials.get_current_price())

OUTPUT:

Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/
Collecting git+https://github.com/sedwards2000/yahoofinancials@encryptionDataFix
  Cloning https://github.com/sedwards2000/yahoofinancials (to revision encryptionDataFix) to /tmp/pip-req-build-6g1jpfqp
  Running command git clone -q https://github.com/sedwards2000/yahoofinancials /tmp/pip-req-build-6g1jpfqp
  Running command git checkout -b encryptionDataFix --track origin/encryptionDataFix
  Switched to a new branch 'encryptionDataFix'
  Branch 'encryptionDataFix' set up to track remote branch 'encryptionDataFix' from 'origin'.
Requirement already satisfied: beautifulsoup4 in /usr/local/lib/python3.8/dist-packages (from yahoofinancials==1.6) (4.11.1)
Requirement already satisfied: pytz in /usr/local/lib/python3.8/dist-packages (from yahoofinancials==1.6) (2022.6)
Requirement already satisfied: soupsieve>1.2 in /usr/local/lib/python3.8/dist-packages (from beautifulsoup4->yahoofinancials==1.6) (2.3.2.post1)
Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/
Requirement already satisfied: pycryptodome in /usr/local/lib/python3.8/dist-packages (3.16.0)
Apple current price in $ 131.86

@Usbasuthkar
Copy link

Usbasuthkar commented Dec 25, 2022

Hey, I am new to GitHub and I faced the same issue and now here is the fix but I don't know what to do with the code given, like should I execute it or what am I suppose to do

Hi!

You have to change the source code yourself applying the changes highlighted in the pull request. 62119be

You have to modify yahoofinancials module’s __init__.py file; there are two ways to find it:

  • use your IDE "Find in Files / Scope" (or smth like that) function searching for the original code, for example "track the last get timestamp to add a minimum delay between gets - be nice!"
  • or go to the virtual environment folder and follow the path like: lib > site-packages > yahoofinancials > __init__.py

Apply the changes and that's it! Just make sure you have "pycryptodome" module installed

It worked thanks a lot

@JECSand
Copy link
Owner

JECSand commented Jan 2, 2023

Looking at the MR now @divyankm

@JECSand
Copy link
Owner

JECSand commented Jan 2, 2023

@githubkingchamp I merged in the fix from @sedwards2000 and just released v1.7. Please let me know if there's anymore issues, I'll be more attentive.

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