JECSand / yahoofinancials

A powerful financial data module used for pulling data from Yahoo Finance. This module can pull fundamental and technical data for stocks, indexes, currencies, cryptos, ETFs, Mutual Funds, U.S. Treasuries, and commodity futures.
https://pypi.python.org/pypi/yahoofinancials
MIT License
896 stars 214 forks source link

HTTP 401 Unauthorized #152

Closed apunkt closed 11 months ago

apunkt commented 11 months ago

Since this morning I get the following error when calling .get_current_price():

in <module> current_price = yahoo_financials.get_current_price() File "/usr/local/lib/python3.8/dist-packages/yahoofinancials/yf.py", line 226, in get_current_price return self._stock_price_data('regularMarketPrice') File "/usr/local/lib/python3.8/dist-packages/yahoofinancials/yf.py", line 162, in _stock_price_data price_data = self.get_stock_price_data() File "/usr/local/lib/python3.8/dist-packages/yahoofinancials/yf.py", line 99, in get_stock_price_data return self.get_clean_data(self.get_stock_tech_data('price'), 'price') File "/usr/local/lib/python3.8/dist-packages/yahoofinancials/etl.py", line 591, in get_stock_tech_data return self.get_stock_data(tech_type=tech_type) File "/usr/local/lib/python3.8/dist-packages/yahoofinancials/etl.py", line 561, in get_stock_data dict_ent = self._create_dict_ent(self.ticker, statement_type, tech_type, report_name, hist_obj) File "/usr/local/lib/python3.8/dist-packages/yahoofinancials/etl.py", line 517, in _create_dict_ent re_data = self._get_historical_data(YAHOO_URL, r_map, tech_type, statement_type) File "/usr/local/lib/python3.8/dist-packages/yahoofinancials/etl.py", line 244, in _get_historical_data self._request_handler(url, config.get("response_field")) File "/usr/local/lib/python3.8/dist-packages/yahoofinancials/etl.py", line 205, in _request_handler raise ManagedException("Server replied with server error code, HTTP " + str(response.status_code) + yahoofinancials.etl.ManagedException: Server replied with server error code, HTTP 401 code while opening the url: https://query2.finance.yahoo.com/v10/finance/quoteSummary/22ua.de?modules=price&formatted=False&lang=en-US&region=US&corsDomain=finance.yahoo.com

Server response is "Unauthorized" > "Invalid crumb"

.get_historical_price_data() however continues to work.

Please advise.

monolidth commented 11 months ago

The implementation is broken. You need to pass &crumb=<the crumb> in the url.

krisannaert commented 11 months ago

how to get the crumb?

jobidon commented 11 months ago

getting the same error: {"finance":{"result":null,"error":{"code":"Unauthorized","description":"Invalid Crumb"}}}

Edison0019 commented 11 months ago

I'm getting the error issue when using the one of the get_* methods

JECSand commented 11 months ago

Sorry I have been out on vacation, let me address this issue.

JECSand commented 11 months ago

@apunkt @monolidth @jobidon @Edison0019

I just released v1.16 to PyPI, which includes a fix for this issue. My apologies for not getting this out sooner. I'll be keeping an eye out for any further reported problems.

Closing this issue.

jobidon commented 11 months ago

oh, you didn't get the memo? You are not allowed to take vacations anymore... Especially in the summer... Ever... jk! Seriously though, thanks so much for looking into this so quickly! Very much appreciated!