ZhuLinsen/daily_stock_analysis · error · DataFetchError
{market_label} {stock_code} 获取失败: 暂无可用数据源
Error message
{market_label} {stock_code} 获取失败:
暂无可用数据源 What it means
Raised by DataFetcherManager before any network call: after market detection (us/hk/jp/kr/tw/cn) and capability filtering ('daily_data'), zero fetchers remain. This is a configuration/availability failure, not a network failure — the failover loop never starts.
Source
Thrown at data_provider/base.py:1304
# - 未配置长桥: YFinance 为首选(美股), 通用 fetcher 循环(港股)
# - 美股指数: 始终 YFinance 为首选(Longbridge 不提供指数K线)
is_us_index = is_us_index_code(stock_code)
is_us = is_us_index or is_us_stock_code(stock_code)
is_hk = (not is_us) and _is_hk_market(stock_code)
is_jp = (not is_us) and (not is_hk) and _is_jp_market(stock_code)
is_kr = (not is_us) and (not is_hk) and _is_kr_market(stock_code)
is_tw = (not is_us) and (not is_hk) and _is_tw_market(stock_code)
market = "us" if is_us else "hk" if is_hk else "jp" if is_jp else "kr" if is_kr else "tw" if is_tw else "cn"
if market != "cn":
fetchers = self._filter_daily_fetchers_for_market(fetchers, market)
fetchers = self._filter_fetchers_by_capability(fetchers, capability="daily_data")
total_fetchers = len(fetchers)
if total_fetchers == 0:
market_label = "美股指数" if is_us_index else "美股" if is_us else "港股" if is_hk else "台股" if is_tw else "A股"
error_summary = f"{market_label} {stock_code} 获取失败:\n暂无可用数据源"
logger.error(f"[数据源终止] {stock_code} 获取失败: {error_summary}")
raise DataFetchError(error_summary)
# 美股(含美股指数)使用专用路由;港股走下方通用数据源循环
# Failover chain: Finnhub(P2) -> AlphaVantage(P3) -> Yfinance(P4) -> Longbridge(P5)
# When Longbridge preferred: Longbridge -> Finnhub -> AlphaVantage -> Yfinance
if is_us:
prefer_lb = self._longbridge_preferred(capability="daily_data") and not is_us_index
if is_us_index:
# 指数始终 YFinance 首选(Longbridge 不提供指数K线)
source_order = ["YfinanceFetcher", "FinnhubFetcher"]
elif prefer_lb:
source_order = ["LongbridgeFetcher", "FinnhubFetcher", "AlphaVantageFetcher", "YfinanceFetcher"]
else:
source_order = ["FinnhubFetcher", "AlphaVantageFetcher", "YfinanceFetcher", "LongbridgeFetcher"]
market_label = "美股指数" if is_us_index else "美股"
for order_index, src_name in enumerate(source_order):
fallback_to = (
source_order[order_index + 1]View on GitHub (pinned to 5159bd72e8)
Solutions
- Inspect manager.available_fetchers to see which sources are actually registered and alive.
- Enable/configure at least one data source that covers the failing market and declares the daily_data capability (e.g. YfinanceFetcher for US/JP/KR/TW, AkShare for A-share/HK).
- If you added a custom fetcher, make sure its capability list includes 'daily_data' and it passes the market filter for the requested code.
Example fix
# before: run headless with no keys -> 美股 AAPL 获取失败: 暂无可用数据源 # after: .env YFINANCE_ENABLED=true # or provide FINNHUB_API_KEY=...
Defensive patterns
Strategy: validation
Validate before calling
names = manager.available_fetchers
if not names:
raise SystemExit('no data sources configured — check .env / API keys') Try / catch
try:
df = manager.get_daily_data(code, ...)
except DataFetchError as e:
if '暂无可用数据源' in str(e):
# configuration problem, fail fast — retrying is pointless
raise Prevention
- At startup, assert available_fetchers is non-empty and covers every market in your watchlist.
- Wire required API keys in .env / CI secrets and keep .env.example in sync.
- When adding a market (JP/KR/TW), first verify at least one fetcher declares daily_data for it.
When it happens
Trigger: get_daily_data on a market whose fetchers were all removed by _filter_daily_fetchers_for_market or _filter_fetchers_by_capability, e.g. a JP/KR/TW market where no fetcher supports daily_data, or all configured sources are disabled/unavailable.
Common situations: Running with a minimal .env (no API keys) so fetchers self-disable; adding a new market (JP/KR/TW) without a capable fetcher; capability metadata on a custom fetcher missing 'daily_data'.
Related errors
- 大盘复盘未返回可持久化报告
- {call_name} 调用超过 {wait_seconds:g}s,已放弃等待
- {call_name} 调用进程未返回结果
- AkshareFetcher 不支持美股 {stock_code},请使用 YfinanceFetcher 获取正确的复
- Akshare 所有渠道获取失败: {last_error}
AI-assisted analysis of ZhuLinsen/daily_stock_analysis@5159bd72e8 (2026-08-15).
Data as JSON: /api/errors/fd9e95feeefcd59c.
Report an issue: GitHub.