Gateway & Routing · recorded 2026-08-29 · applies to 1 tool(s) ✓ Verified

Problem: yfinance history times out in CN — cookie/crumb fetch failures, curl (28) —— Trove problem library

Verified 2026-08-29yfinance history always times out — upgrade to >=1.7 and use a curl_cffi firefox-fingerprint session with a proxy (yf.download(..., proxy='socks5h://...')).

Quick fix

# One-liner: upgrade to yfinance>=1.7 and use curl_cffi's firefox-fingerprint session with a proxy (SOCKS5 port per your proxy)
pip install -U yfinance curl_cffi && python3 -c "import yfinance as yf; yf.download('AAPL', period='5d', proxy='socks5h://127.0.0.1:7890')"

Use your local proxy's actual port (7890 in the example); this one command covers both "version too old" and "channel unreachable".

What you will run into

yf.Ticker(...).history(...) fails right away: the log first shows Cookie fetch from fc.yahoo.com failed (Timeout), continuing without it, then Cookie/crumb fetch failed ... continuing without crumb, and finally Failed to get ticker ... curl: (28) Connection timed out after 10001 milliseconds.

Most common on direct CN connections, or when a proxy only allows some domains — even the chart endpoint can work while history keeps hanging.

Why this happens

Before fetching data, yfinance requests two helper endpoints: fc.yahoo.com for a Cookie and query1.finance.yahoo.com/v1/test/getcrumb for a crumb.

These domains generally time out/unreachable on direct CN connections; if a proxy only allows some domains, you get the "chart works, history hangs" illusion.

ScenarioSymptom (measured)
CN directfc.yahoo.com timeout → crumb fails → curl: (28)
Proxy with partial allowlistchart works, history hangs (one of fc/query1/query2 missing)
1.6.xcrumb fetch fails → hard failure
1.7.xcookie/crumb failures are warnings only; auto-rotates query1/query2; still fails if the data channel is entirely unreachable

yfinance fetching historical data is a "three-endpoint chain": first fc.yahoo.com for a Cookie, then query1.finance.yahoo.com/v1/test/getcrumb for a crumb, and only then the data endpoints with the crumb — the first two are prerequisites, and if either is unreachable, history cannot be fetched.

The "chart works but history hangs" appearance comes from partial allow-listing: the proxy allowed the data domains but missed one of fc/query1/query2. Version differences change failure semantics: 1.6.x fails outright on crumb errors;

1.7.x downgrades to warnings and automatically rotates query1/query2 (still fails when the data channel is wholly unreachable).

Deterministic takeaway: on curl: (28) timeout, locate which hop fails — curl the three domains separately; for direct domestic connections, route all three through the proxy (or switch data sources entirely); in proxy setups, allow-list fc.yahoo.com and query1/query2.finance.yahoo.com all together;

on 1.7.x, "warnings but data comes out" is normal degradation, not a fault; fixed diagnostic: failure at the crumb stage = the prerequisite chain is broken; at the data stage = the data channel is broken.

Step by step

1. Upgrade yfinance — Required

pip install -U yfinance curl_cffi

≥1.7 tolerates cookie/crumb failures and auto-rotates query1/query2.

2. Go through a proxy (when direct is blocked) — Required

Use a curl_cffi session with a firefox fingerprint and HTTP/2, pointing both http/https at the proxy (measured: SOCKS5 and HTTP proxies both work):

python3 - <<'EOF'
from curl_cffi import requests
s = requests.Session(impersonate="firefox", proxies={"http": "socks5h://127.0.0.1:7890", "https": "socks5h://127.0.0.1:7890"})
EOF

Replace SOCKS5 with your actual port; socks5h routes DNS through the proxy too.

3. Allow all Yahoo endpoints in proxy rules — Required

fc.yahoo.com + query1/query2.finance.yahoo.com must all be reachable. Missing any one = partial timeouts (the article's scenario).

4. Locate the stuck point — Diagnose

yf.enable_debug_mode

See which domain the log stops at; then with the same session GET https://query1.finance.yahoo.com/v8/finance/chart/... directly to compare reachability.

How to confirm it works

History requests return data normally (measured output shape: 14 rows):

yf.Ticker("AAPL").history(period="5d")
→ DataFrame (14 rows × 7 columns, Open/High/Low/Close/Volume...)

No more Cookie/crumb fetch failed or curl: (28) timeouts in the log.

Other environments

EnvironmentNotes
WSL directMeasured blocked; full error chain reproduced (fc.yahoo.com timeout → crumb fail → curl 28)
Windows-side SOCKS5 proxy (127.0.0.1:7890)Measured all pass: chart 200 (HTTP/3) + history OK (14 rows)
1.7.0 + hosts-block fc.yahoo.comMeasured: only cookie fails, still succeeds
1.7.0 + also block query1Measured: crumb fails, still succeeds (auto-switches to query2)
Proxy missing a domainPartial timeouts; allow fc/query1/query2 all

Symptom

yf.Ticker(...).history(...) fails repeatedly; the log first shows Cookie fetch from fc.yahoo.com failed (Timeout), continuing without it, Cookie/crumb fetch failed ... continuing without crumb, then Failed to get ticker ... curl: (28) Connection timed out after 10001 milliseconds. Typical: direct China-network access to Yahoo, or a proxy that only whitelists part of the domains (Chart API works but history hangs).

Cause

Before fetching data, yfinance calls two helper endpoints: fc.yahoo.com for the cookie and query1.finance.yahoo.com/v1/test/getcrumb for the crumb. From China these domains time out / are blocked on direct connections; with a partially-whitelisted proxy you get the "chart connects, history hangs" illusion. Version difference (measured): 1.6.x fails outright when the crumb fetch fails; 1.7.x relaxed this (cookie/crumb failure is only a warning, data endpoints can fail over between query1/query2), but it still fails when the whole data channel is unreachable.

Solution

  1. Direct timeout → use a proxy: both SOCKS5 and HTTP proxies measured working (e.g. socks5h://127.0.0.1:7890), combined with a curl_cffi session (Firefox fingerprint + HTTP/2):

requests.Session(impersonate="firefox", http_version=CurlHttpVersion.V2TLS, proxies={"http": proxy, "https": proxy})

  1. Whitelist all Yahoo endpoints in the proxy rules: fc.yahoo.com + query1/query2.finance.yahoo.com must all be reachable; missing one domain = partial timeouts (the article's scenario).
  2. Upgrade yfinance ≥ 1.7: tolerant to cookie/crumb failure + endpoint failover lowers intermittent failures.
  3. Locate the bottleneck: yf.enable_debug_mode shows which domain the log hangs on; with the same session, get("https://query1.finance.yahoo.com/v8/finance/chart/...") directly for comparison.
Verification Evidence
  • Local test (2026-08-29): yfinance 1.7.0 + curl_cffi 0.16.2, WSL direct vs Windows-side SOCKS5 proxy (127.0.0.1:7890).
  • Direct (blocked): full repro of the article's error chain (fc.yahoo.com timeout → crumb failure → curl: (28) Connection timed out).
  • Proxy all-open: chart 200 (HTTP/3) + history OK (14 rows).
  • Mechanism detail: hosts-blocking fc.yahoo.com → 1.7.0 still succeeds with only cookie failure; then blocking query1 → crumb failure still succeeds (auto failover to query2) — verifies the version difference.

Evidence details kept locally (2026-08-29)

Applicable tools (1)

This problem is linked from the tool pages below — reachable from either side.

yfinance

Source & evidence

Recorded Verified ✓ VerifiedApplies to 1 tool(s)
Entries contain locally measured or reviewable-source solutions; unmeasured items are explicitly labeled.

Source: https://www.cnblogs.com/amosli/p/22652811

← Gateway & Routing domain | Problem Catalog Experience | Facing another issue? Go to the Helpdesk