yfinance icon indicating copy to clipboard operation
yfinance copied to clipboard

[0.2.61] Still 429 Error: Too Many Requests after trying previous fixes

Open twnlawr opened this issue 7 months ago • 16 comments

Hi all,

I looked at #2480, #2483 and #2422 for solutions, upgraded yfinance to 0.2.61, tried cull_cffi impersonate, but still getting the same error in my local IDE with Python version 3.11.7.

Simple code that replicates the error: import yfinance as yf baba = yf.Ticker("BABA") print(baba.info)

Debug log from yf.enable_debug_mode() DEBUG get_raw_json(): https://query2.finance.yahoo.com/v10/finance/quoteSummary/BABA DEBUG Entering get() DEBUG url=https://query2.finance.yahoo.com/v10/finance/quoteSummary/BABA DEBUG params={'modules': 'financialData,quoteType,defaultKeyStatistics,assetProfile,summaryDetail', 'corsDomain': 'finance.yahoo.com', 'formatted': 'false', 'symbol': 'BABA'} DEBUG Entering _get_cookie_and_crumb() DEBUG cookie_mode = 'basic' DEBUG Entering _get_cookie_and_crumb_basic() DEBUG reusing cookie DEBUG reusing crumb DEBUG Exiting _get_cookie_and_crumb_basic() DEBUG Exiting _get_cookie_and_crumb() DEBUG response code=429 DEBUG toggling cookie strategy basic -> csrf DEBUG Entering _get_cookie_and_crumb() DEBUG cookie_mode = 'csrf' DEBUG Entering _get_crumb_csrf() DEBUG Failed to find "csrfToken" in response DEBUG Exiting _get_crumb_csrf() DEBUG toggling cookie strategy csrf -> basic DEBUG Entering _get_cookie_and_crumb_basic() DEBUG loaded persistent cookie DEBUG reusing cookie DEBUG crumb = 'Edge: Too Many Requests' DEBUG Exiting _get_cookie_and_crumb_basic() DEBUG Exiting _get_cookie_and_crumb() DEBUG response code=429 DEBUG Exiting get()

Please shed some light on whether I missed something on previous issues or this problem recurs again. Thanks a lot the amazing dev team.

twnlawr avatar May 27 '25 15:05 twnlawr

How many requests are you sending?

ValueRaider avatar May 27 '25 18:05 ValueRaider

I get the Too many Requests error with just one yf.Ticker("MSFT") request while running 0.2.61 as well. This tool has been down for a couple of weeks? As I can see. What is the yfinance community suggesting is the best course to restore data updates? My needs are small and I would rather not rewrite my code for TIINGO or TwelveData ... but might have to if this continues

edwardtilley avatar May 27 '25 19:05 edwardtilley

Has anyone tried the https://github.com/ranaroussi/yfinance/commit/4a91008c09055c2566abadd7d3d22aaa8cb54442 hotfix ... ls it a good or terrible idea to update my 0.2.61 files with this workaround?

edwardtilley avatar May 27 '25 19:05 edwardtilley

@edwardtilley you can always rollback https://ranaroussi.github.io/yfinance/development/running.html

ValueRaider avatar May 27 '25 19:05 ValueRaider

I was hoping to confirm was this the latest commit and was it a proven solution first... Without this double check that this it is working, its a time waster and I haven't done the rollback before either, so I'd rather try it on code known to be tested and working . Ideally :)

edwardtilley avatar May 27 '25 20:05 edwardtilley

yfinance latest release works for the vast majority of users. Most of the exceptions are proven to have old versions.

If you have problem with 0.2.61, then we need you to test and report back.

ValueRaider avatar May 27 '25 20:05 ValueRaider

I wish I was a better reporter. Would it help to share the full detail of the error? I assume yes, so I will post it in a couple of hours.

edwardtilley avatar May 27 '25 20:05 edwardtilley

@ValueRaider I only sent 1 request and it didn't work. I tried with the exact simple code that replicates the error and nothing else.

twnlawr avatar May 28 '25 01:05 twnlawr

I got the same problem.

qqwqqw689 avatar May 28 '25 08:05 qqwqqw689

I got the same problem with yfinance-0.2.61

youngmihuang avatar May 28 '25 16:05 youngmihuang

I've noticed that finance.yahoo.com will return a 429 Too Many Requests under certain circumstances regardless of the number of requests.

For example, when I use a local HTTPS proxy that establishes the TLS connection to yahoo directly, a single request causes the 429 Too Many Requests response.

If I switch to a SOCKS5 proxy (just relaying the connection), requests work as expected. If I don't use a proxy at all, the same code also works as expected.

I discovered this while trying to inspect the network traffic with my HTTPS proxy.

My best guess is that finance.yahoo.com is trying to detect and prevent unusual usage even if it's a single request. The "Too Many Requests" is really just the generic response they use for possibly a set of detected behaviors. (I'm not really sure how they detect the local HTTPS proxy though other than possibly how the proxy negotiates the TLS connection differently than a browser or curl_cffi.)

Anyway, just realize that "Too Many Requests" may not be the real underlying issue and maybe try various (i.e. from different IPs) direct, non-proxy, non-shared vpn connections to help diagnose network level issues.

keithbentrup avatar May 29 '25 20:05 keithbentrup

Thanks - will give it a try. I have seen the error with and without VPN - will look into the other suggestions and I agree it's a network level block. I'm on a DHCP provided cable internet so I'm not sure how I'll change IPs... Suggestions welcome and I'll share research also.

On Thu, May 29, 2025, 4:50 p.m. Keith Bentrup @.***> wrote:

keithbentrup left a comment (ranaroussi/yfinance#2518) https://github.com/ranaroussi/yfinance/issues/2518#issuecomment-2920552743

I've noticed that finance.yahoo.com will return a 429 Too Many Requests under certain circumstances regardless of the number of requests.

For example, when I use a local HTTPS proxy that establishes the TLS connection to yahoo directly, a single request causes the 429 Too Many Requests response.

If I switch to a SOCKS5 proxy (just relaying the connection), requests work as expected. If I don't use a proxy at all, the same code also works as expected.

I discovered this while trying to inspect the network traffic with my HTTPS proxy.

My best guess is that finance.yahoo.com is trying to detect and prevent unusual usage even if it's a single request. The "Too Many Requests" is really just the generic response they use for possibly a set of detected behaviors. (I'm not really sure how they detect the local HTTPS proxy though other than possibly how the proxy negotiates the TLS connection differently than a browser or curl_cffi.)

Anyway, just realize that "Too Many Requests" may not be the real underlying issue and maybe try various (i.e. from different IPs) direct, non-proxy, non-vpn connections to help diagnose network level issues.

— Reply to this email directly, view it on GitHub https://github.com/ranaroussi/yfinance/issues/2518#issuecomment-2920552743, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANZ245XWAQGYWJLVN5TK3RL3A5XIZAVCNFSM6AAAAAB6AMHIJ6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDSMRQGU2TENZUGM . You are receiving this because you were mentioned.Message ID: @.***>

edwardtilley avatar May 29 '25 22:05 edwardtilley

yf_tick = yf.Ticker("MSFT") print(yf_tick.info) Runs without error but the print result is: None

yf_tick = yf.Ticker("MSFT").info Error - Too many requests

This was consistent with VPN USA IP and Japan IP, more and less trusted TOR servers on Proton VPN

edwardtilley avatar May 30 '25 14:05 edwardtilley

Same for me as @edwardtilley

karanbosamia avatar Jun 12 '25 05:06 karanbosamia

This solved now?

ValueRaider avatar Jul 28 '25 19:07 ValueRaider

Still not solved for python 3.9, win 11 and the lastest version 0.2.65

thisisreallife avatar Jul 29 '25 14:07 thisisreallife