-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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 #1407
Comments
Agreed. I noticed 12 hours ago Yahoo was more sensitive to spam, but only now a total block. FYI I've just released 0.2.10 which fixes the backup decrypt methods but doesn't help (I hoped it would), so don't feel pressured to upgrade 0.2.9. Unless you want to debug and fix, then definitely upgrade. |
If you came to report same issue, just upvote the top comment. Keep this thread clean and constructive. |
Don't see any obvious change to This is the Javascript we think they use to encrypt: https://s.yimg.com/uc/finance/dd-site/js/main.e0c853d8cea2b75a5208.min.js |
Why are the comments being deleted? |
@jasmohan-narula Because all they essentially say is "I have issue too", contributing nothing. Thread quickly gets messy, some of us want to discuss problem. |
Hello, I have investigated and I noticed different things during my testing using : _get_decryption_keys_from_yahoo_js(self, soup) always return an empty array of keys for me and I get the error : For function _get_decryption_keys_from_yahoo_js in data.py, line 218 : So I tried to make this if work and I replace the instruction before : To : And the method now return the concatenate result of the last 4 keys :
I guess the code can now try to decrypt the store with the non-empty keys : When decrypt_cryptojs_aes_stores(data, keys) is called .... It seems that the keys contained in the plugin object doesn't work anymore? I hope it helped, I'll try go deeper in the code to see what makes the decryption failed. |
I've created branch |
Since the encryption method changed from Yahoo Finance's backend side, does this mean that all of yfinance package is not usable, not even the previous versions ? |
@snowgato Off topic but it works. Just pip upgrade your requests and urllib3. dpguthrie/yahooquery#143 |
The json loaded from root.App.main always comprises 10004 key/value pairs, but simply joining the last 4 values is no longer working. The password needed to disentangle "stores" is generated by a javascript function supplied in "main.xxxxxxxxxxxxxxxxxx.modern.js". The version of this file is indicated by the hash "xxxxxxxxxxxxxxxxxx". The javascript code in this file changes with every version and seems to be heavily obfuscated. I got the same version of "main.xxxxxxxxxxxxxxxxxx.modern.js" for all pages I called on the same day, and another version on the next day. All pages delivered with a certain version of "main.xxxxxxxxxxxxxxxxxx.modern.js" are including the same 10004 key/value pairs in root.App.main, but the order of these 10004 key/values is changed with each page call. I loaded a stock page in a webbrowser and then opened the inspection console (F12). After setting a breakpoint in "main.xxxxxxxxxxxxxxxxxx.modern.js" I could scrap the password from an internal variable. The password is still a concatenate of 4 of the values comprised in root.App.main and it is 128 bytes long. After manually copying the password into python code, I could read the "stores" dict. The javascript code in "main.xxxxxxxxxxxxxxxxxx.modern.js" is obfuscated. Variable and function names seem to change in diffrenet versions. The decryption of the json string is done in this function call: return s.context.dispatcher.stores=JSON.parse(function(e,t){return c().decrypt(e,t).toString(... In this case, a variable named "e" is holding the entangled content of "stores" and a variable name "t" comprising the 128 bytes password. This password can be used to decrypt the "stores" in all pages delivered with that particular version of "main.xxxxxxxxxxxxxxxxxx.modern.js". I have no idea, how to automate the generation of the password with "main.xxxxxxxxxxxxxxxxxx.modern.js". Maybe someone experienced in javascript will find a solution. The way Yahoo is wrapping their data is by no means proper encryption. It is just a kind of obfuscation by misusing standard functions from cryptography. |
You don't, trust me. If |
Do you have any sample store decrypted data? |
@asafravid Can you move your |
@ValueRaider Sure |
@ValueRaider Can anyone succeeds getting I found that |
@qianyun210603 The current status is top post of this thread, there isn't a secret work group. |
Is it possible that the decrypt_cryptojs_aes_stores() function is no longer valid to decrypt the yahoo finance page after the update ? I tried to hardcode the input, with the last 4 key/pairs combined 128bytes password to run decrypt_cryptojs_aes_stores()._decrypt() function, an error araies from the line 133
It araises the following assumptions:
As a beginner, I am here to learn. Please bare with me for my lack of understanding with the repo and lack of knowledge in modern cryptography. |
No, it still works, people have manually extracted key from the Javascript and successfully decrypted. Read the top post, and maybe the thread. |
To the next person who asks when will this be fixed? I assume that this will never get fixed. It doesn't seem to be the direction that the broader community wants to go, and it makes sense. I finally had the time to go rewrite all of my stuff and took an opportunity to re-architect everything. yahooquery was trivially easy to use - I would say simpler than yfinance - and leaps and bounds faster for data that would have come from I had implemented my own caching layer on top of yfinance which I kept for yahooquery (this was mostly to minimize any unneeded requests to yahoo) and ported that over without issue. For anyone concerned about speed because lack of caching... assuming you know how to build a cache, this is only like 50 lines of code in python to create a basic symbol + data segment cache. All in all, it took me on the order of 10 hours to reimplement the code that deals with sourcing data from yahoo. Thanks for all of the past work building and maintaining yfinance, @ValueRaider et al. |
Great! Would you share it? |
I have no problem with community wanting to go in a different direction, whether that's moving |
Any updates? |
I have the following problem when using yfinance. The code is: import yfinance as yf output is : `- AAPL: No summary info found, symbol may be delisted None` my yfinance version is 0.2.10
I don't know what happen, who can help solve this issue thanks |
I don't see the decryption being fixed - too difficult, and probably Yahoo don't want us to fix scraping. So what next? @ranaroussi's preference is replacing the scraping with API requests like |
Closing this as decryption will never be fixed. Financials tables now fully ported to use API - was already 95% done just had to stop scraping the keys, 5 minute fix. |
known issues b/t yahoo finance updating layout and yfinance lib lagging see ranaroussi/yfinance#1407,
Looks like more encryption issues from yahoo.com
Exception: yfinance failed to decrypt Yahoo data response
[ Basically affects everything except price history @ValueRaider ]
Using Python version 3.11.0
yf version 0.2.9
@ValueRaider hijacking top post
[2023-06-23] Update! Latest release fixes financials tables (and removes decryption code).
What is happening? In December 2022 Yahoo began encrypting webpage data, maybe to block scraping. Now, Yahoo is regularly changing their encryption key, we think every day (and maybe multiple times a day). Without an automated system to extract key from their webpage (work in progress), fixing decryption requires a volunteer to manually extract the new key and provide to developers to upload to
yfinance
.Help neededNeed a Javascript dev to write a script that extract AES decryption key from obfuscated JS that Yahoo uses to en/decrypt. The key is there plaintext, just need to automate extraction. The JS changes every day so limited scope to hardcode (use Git branchhotfix/decryption
to print today's JS url). Don't worry about sandboxing etc, end users won't execute this.Script should be separate toyfinance
codebase. I expect your only interaction withyfinance
is testing the extracted key works by putting inyfinance/data.py
Useful comments:"The decryption of the json string is done in this function call:""Need to execute the JS in e.g. js2py""Obfuscation done using the popular javascript-obfuscator tool, easily reversible""I've been told can extract key via breakpoint in Firefox""fwiw, youtube-dl faced similar issues regarding encryption. They ended up implementing their own (very limited) JS interpreter"Progress updates
2023-06-21
Update your yfinance! Latest release fixes financials tables and removes decryption code.
2023-06-04
Obvious that the decryption won't be fixed. See last message for plan.
2023-03-25
Ticker.info
fixed by fetching from API. Financials still broken.2023-02-17
Yahoo finally started using a new encryption key not in
yfinance
backup list of keys, so decryption failing. Inevitable. Surprised it took 4 days.2023-02-13
What is the "backup decryption method"? This is simply yfinance fetching decryption keys from this GitHub project website instead of extracting from Yahoo.com. Was broken in 0.2.9 but fixed in 0.2.10. Today worked for many thanks to a key uploaded yesterday. Discussion continues on a decent system for extracting & sharing decryption key.
workaround - yahooquery
Python module
yahooquery
is a functional alternative toyfinance
. Instead of scraping webpages it accesses Yahoo's undocumented API. Not encrypted and faster, but lacksearnings_dates
. GitHub DocumentationThe text was updated successfully, but these errors were encountered: