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

Exception: yfinance failed to decrypt Yahoo data response with hardcoded keys, contact developers #1329

Closed
DolevAlgam opened this issue Jan 23, 2023 · 71 comments · Fixed by #1336

Comments

@DolevAlgam
Copy link

DolevAlgam commented Jan 23, 2023

I use Python 3.8
Installed yfinance 0.2.4
I'm pulling the info of a ticker using this code:
info = yf.Ticker(symbol).info
And I'm getting this error message:

Exception("Yahoo has again changed data format, yfinance now unsure which key(s) is for decryption: '80226cfb77c7'-><class 'str'> , '80226cfb77c7'-><class 'str'> , '80226cfb77c7'-><class 'str'> , '80226cfb77c7'-><class 'str'> , '80226cfb77c7'-><class 'str'> , '80226cfb77c7'-><class 'str'> , '80226cfb77c7'-><class 'str'> , '80226cfb77c7'-><class 'str'> ,
And it continues with a ton of <class 'str'> like above.

Does someone know how to fix it?

EDIT from @ValueRaider
In case you're confused by title not matching this top post - I edited title to reflect the latest error message. Discussion below still very relevent.

EDIT: New discussion starting in #1407

@ValueRaider
Copy link
Collaborator

ValueRaider commented Jan 23, 2023

I've quickly tested and working for me.

Error message tells us there are 8 fields when yfinance expected 1. But there is a bug in generating that error message, that's why all print same - can you try again with Git branch hotfix/decryption.

@BugByteMan
Copy link

I updated my code to handle the exception and retry the request. That has fixed the issue for me.

@rschaub-epicor
Copy link

rschaub-epicor commented Jan 23, 2023

I use Python 3.8 Installed yfinance 0.2.4 I'm pulling the info of a ticker using this code: info = yf.Ticker(symbol).info And I'm getting this error message:

Exception("Yahoo has again changed data format, yfinance now unsure which key(s) is for decryption: '80226cfb77c7'-><class 'str'> , '80226cfb77c7'-><class 'str'> , '80226cfb77c7'-><class 'str'> , '80226cfb77c7'-><class 'str'> , '80226cfb77c7'-><class 'str'> , '80226cfb77c7'-><class 'str'> , '80226cfb77c7'-><class 'str'> , '80226cfb77c7'-><class 'str'> ,
And it continues with a ton of <class 'str'> like above.

Does someone know how to fix it?

I'm getting the same error, specifically with ticker FFIV when calling the Tickers.ticker.quarterly_financials attribute.

@mm0
Copy link

mm0 commented Jan 24, 2023

I've quickly tested and working for me.

Error message tells us there are 8 fields when yfinance expected 1. But there is a bug in generating that error message, that's why all print same - can you try again with Git branch hotfix/decryption.

Hi, I have tried this branch and it doesn't seem to fix the issue

@ValueRaider
Copy link
Collaborator

I never said it would fix the decryption.

@mm0
Copy link

mm0 commented Jan 24, 2023

I never said it would fix the decryption.

Okay. In case it helps, the issue seems to occur with paginated/large? requests.

@ValueRaider
Copy link
Collaborator

ValueRaider commented Jan 24, 2023

What will help is posting the fixed error message.

EDIT: WITH THE BRANCH!

hotfix/decryption. See #1080 for how to override PIP.

Repository owner deleted a comment from swilson2020 Jan 24, 2023
Repository owner deleted a comment from rschaub-epicor Jan 24, 2023
@mm0
Copy link

mm0 commented Jan 24, 2023

The error message with your branch is attached
msg.txt

@dschaefer
Copy link

Seems to be the same error message on the branch. It is intermittent. I'm fetching about 24 tickers one at a time in my script and hits pretty randomly.

@dschaefer
Copy link

Seems like the first key works anyway. I simply removed the check for l == 1. Not sure that's the right answer though.

@EmirEgilli
Copy link

EmirEgilli commented Jan 24, 2023

Getting the exact same error since this morning.

Edit: I tried my code over on Jupyter Notebook to see if the issue persists. At the point where a for loop downloads and appends the 'regularMarketPrice', 'sector' and 'industry' info for 41 different tickers to the dataframe, it gives this error at a random point, so i had to run the same snippet multiple times until it doesn't. I found that issue duplicates at "Ticker.info" for yf.

Hope a permanent fix comes soon.

@ValueRaider
Copy link
Collaborator

ValueRaider commented Jan 24, 2023

Thanks @mmm0. Wow that is a lot of keys. I've made two more changes to branch, please run again:

  1. discard new_keys that point to same value - potential fix
  2. improve error message to print the values too

In case not obvious: feedback wanted

@james-stevens
Copy link

Okay. In case it helps, the issue seems to occur with paginated/large? requests.

I'm getting this issue when I run a number of requests, but it seems OK if I just do a single request, by hand

I wonder if they've added some kind of frequency of request checks?

@ValueRaider
Copy link
Collaborator

@AlefTester Start by reading this thread.

@mm0
Copy link

mm0 commented Jan 24, 2023

Thanks @mmm0. Wow that is a lot of keys. I've made two more changes to branch, please run again:

  1. discard new_keys that point to same value - potential fix
  2. improve error message to print the values too

In case not obvious: feedback wanted

msg.txt

Repository owner deleted a comment from AlefTester Jan 24, 2023
@ValueRaider
Copy link
Collaborator

ValueRaider commented Jan 24, 2023

@mm0 That new file has 2x more keys than the previous. And I'm not seeing the usual traffic spike that accompanies Yahoo breaking something (GitHub, Twitter, etc). I don't understand ...

Anyway I've pushed another change to hardcode the key (thanks @ifel), try that.

@hepizoj22
Copy link

hepizoj22 commented Jan 25, 2023

Not sure if this is significant or not, but I was able to get my routines working again by using Ticker() and pulling info individually instead of the Tickers() list call.

Doesn't work for me. I'm using Ticker() since the beginning.
it was working intermittently yesterday(had to restart kernel on jupyter) but now its always this exception.
msg.txt

@dschaefer
Copy link

With the latest hotfix/decryption, I'm now constantly getting:

  File "/opt/homebrew/lib/python3.10/site-packages/cryptography/hazmat/primitives/padding.py", line 101, in _byte_unpadding_check
    raise ValueError("Invalid padding bytes.")
ValueError: Invalid padding bytes.

@dschaefer
Copy link

Using the first key isn't working anymore either. And I'm getting 10004 keys to pick from. They really are trying to make this hard. (And are probably watching this conversation).

@iometrine
Copy link

I updated my code to handle the exception and retry the request. That has fixed the issue for me.

How did you do that ?

@tomekkurzydlak
Copy link

I updated my code to handle the exception and retry the request. That has fixed the issue for me.

How did you do that ?

Not sure if it works today. As for yesterday this issue was quite random, today I'm retrying every 10minutes and got no proper response yet

@james-stevens
Copy link

james-stevens commented Jan 25, 2023

Not sure if this is significant or not, but I was able to get my routines working again by using Ticker() and pulling info individually instead of the Tickers() list call.

I was using this code to get tickers one at a time (including reading all tickers returned each time), with random delays between each get and retrying ones that failed - that was OK for most of yesterday, but is now broken - the JSON returned by get_json_data_stores() is now just empty.

from yfinance import data as yfdata

ask = sys.argv[1].upper()
ticker = yfdata.TickerData(ask)
js = ticker.get_json_data_stores()
store = js["StreamDataStore"]["quoteData"]

Yesterday the problem def seemed to be caused by getting too frequently - like they were throttling the query rate

@Sebastvin
Copy link

Any chance this bug will be fixed today? I'm using yfinance for a project I'm handing in for graduation tomorrow. Previously, the error occurred sometimes and restarting the code solved the problem, but today the error appears every time when I want to run the code

@iometrine
Copy link

waiting for him to fix, you can try to get the information differently

    ticker = yf.Ticker('AAPL')
    hist  = ticker.history(period="1d")
    df = hist.reset_index()
    
    for index, row in df.iterrows():
        index = row['Close']

@ValueRaider
Copy link
Collaborator

ValueRaider commented Jan 25, 2023

Problem seems to have got worse overnight, affecting me now. Please keep thread posts constructive from now.

@dschaefer I've tried ALL the keys, none work.

@Sebastvin Impossible to know chance. Depends on community.

For those that need the data, look into yahooquery Python module. Accesses non-price data different way so not affected by encryption, but their documentation sucks.

@tomekkurzydlak
Copy link

Pull request @ #1353 , test it please

works for me, thank you!

@ValueRaider
Copy link
Collaborator

PIP release out

@jiangoz
Copy link

jiangoz commented Jan 26, 2023

Using version 0.2.7, 'regularMarketPrice' seems to be missing from the Ticker info object

@lucas03
Copy link
Contributor

lucas03 commented Jan 26, 2023

there should be error message, use ticker.basic_info["last_price"] instead

@ValueRaider
Copy link
Collaborator

@jiangoz It should print a message explaining where it's moved to.

@jiangoz
Copy link

jiangoz commented Jan 26, 2023

@jiangoz It should print a message explaining where it's moved to.

I meant it's also not in Ticker.fast_info

Is last_price equivalent to regularMarketPrice ?

@galashour
Copy link

The attribute 'beta' used to be in Ticker.Info, but now couldn't find it also in the metadata or fast_info. Any idea where it was relocated to?

@ValueRaider
Copy link
Collaborator

ValueRaider commented Jan 26, 2023

Is last_price equivalent to regularMarketPrice ?

Yes, and to info["currentPrice"], I never saw a difference.

can't find "beta"

I haven't moved beta. The relocated keys are defined at top of quote.py.

@galashour
Copy link

@ValueRaider you are right, it seems I checked with MSFT and for some reason for that ticker while the attribute exists it returns 'None'. I check with another ticker (e.g., AAPL) and the value was returned.
Thanks.

@eleinv
Copy link

eleinv commented Jan 26, 2023

If I understand correctly the yahoo store now is missing several important information about prices, events etc above the always changes in decryption. Also they have implement throttling due to various test I made.

The Yahoo policy to make difficult to get data will lead eventually to parse the page in a very ugly manner (yahoo.com is dead and with all this changes they will lead to the same road the finance.yahoo.com). @yahoo is it better to spend your time in make data available (as you load them in your page) rather than spend your time in bs changes and make your page slower to load?

@ValueRaider
Copy link
Collaborator

ValueRaider commented Jan 26, 2023

The data was always there, encrypted. They just changed encryption parameters.

Throttling has always existed but it depends on the data you request. info is worst for throttling (10-100/hour), financials maybe better, price data much better (~1000/hour). It may have gotten worse 1-2 years ago but that's before my time, maybe some old-timers can correct me.

@eleinv
Copy link

eleinv commented Jan 26, 2023

The data was there years ago in raw format. Before crumb there was no throttling, now is there an algorithm you must follow to get the data without errors, because of throttling

@dowens375
Copy link

I would like to thank you for your excellent work!

@ValueRaider
Copy link
Collaborator

ValueRaider commented Jan 26, 2023

Only post here if you are experiencing decryption problems. If your issue is different - some might say new - make a New Issue.

Repository owner deleted a comment from machine700 Jan 26, 2023
@waichan-bt
Copy link

Cannot install latest version using "pip3 install yfinance", still showing 0.2.4; when trying to force it by "pip3 install version==0.2.7 yfinance", the version cannot be found.

@bma-diy
Copy link

bma-diy commented Jan 28, 2023

workaround:

info = yf.Ticker(symbol).info

type(info)
yfinance.scrapers.quote.InfoDictWrapper

convert it to dictionary and your code should work:

info = dict(info)

@ValueRaider ValueRaider unpinned this issue Feb 6, 2023
Repository owner deleted a comment from vishwesh5544 Feb 7, 2023
Repository owner deleted a comment from vishwesh5544 Feb 7, 2023
Repository owner deleted a comment from vishwesh5544 Feb 7, 2023
@ValueRaider
Copy link
Collaborator

@Dr-DFTD3 @dkim777 @EmirEgilli I've started a new Issue thread for this. #1407

Repository owner deleted a comment from EmirEgilli Feb 8, 2023
Repository owner deleted a comment from dkim777 Feb 8, 2023
Repository owner deleted a comment from Dr-DFTD3 Feb 8, 2023
Repository owner deleted a comment from Travis-Barton Feb 10, 2023
Repository owner locked and limited conversation to collaborators Feb 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.