microsoft/qlib · error · ValueError
request error
Error message
request error
What it means
Raised inside _get_eastmoney of get_us_symbols (scripts/data_collector/utils.py:306) when ak.get_us_stock_name() returns fewer than 8000 symbols. Like 590, it is a completeness sentinel: the akshare call 'succeeded' but the list is implausibly small for the US market, so the scraper treats it as a failed/incomplete fetch. The @deco_retry wrapper retries it before the error propagates.
Source
Thrown at scripts/data_collector/utils.py:306
def get_us_stock_symbols(qlib_data_path: [str, Path] = None) -> list:
"""get US stock symbols
Returns
-------
stock symbols
"""
import akshare as ak # pylint: disable=C0415
global _US_SYMBOLS # pylint: disable=W0603
@deco_retry
def _get_eastmoney():
df = ak.get_us_stock_name()
_symbols = df["symbol"].to_list()
if len(_symbols) < 8000:
raise ValueError("request error")
return _symbols
@deco_retry
def _get_nasdaq():
_res_symbols = []
for _name in ["otherlisted", "nasdaqtraded"]:
url = f"ftp://ftp.nasdaqtrader.com/SymbolDirectory/{_name}.txt"
df = pd.read_csv(url, sep="|")
df = df.rename(columns={"ACT Symbol": "Symbol"})
_symbols = df["Symbol"].dropna()
_symbols = _symbols.str.replace("$", "-P", regex=False)
_symbols = _symbols.str.replace(".W", "-WT", regex=False)
_symbols = _symbols.str.replace(".U", "-UN", regex=False)
_symbols = _symbols.str.replace(".R", "-RI", regex=False)
_symbols = _symbols.str.replace(".", "-", regex=False)
_res_symbols += _symbols.unique().tolist()
return _res_symbolsView on GitHub (pinned to 79633dd950)
Solutions
- Upgrade akshare (pip install -U akshare) — scraper drift in old versions is the usual cause of truncated tables.
- Retry after a delay; @deco_retry already retries, so add a coarser outer retry/backoff.
- Verify manually: python -c "import akshare as ak; print(len(ak.get_us_stock_name()))" — if persistently < 8000, the akshare source needs fixing.
- get_us_symbols falls back to _get_nasdaq()/_get_nyse() sources in the same function; ensure those network paths also work so the combined list is healthy.
Example fix
# before symbols = get_us_symbols() # eastmoney path keeps returning short list # after pip install -U akshare # then re-run symbols = get_us_symbols()
Defensive patterns
Strategy: retry
Validate before calling
import akshare as ak
df = ak.get_us_stock_name()
if len(df) < 8000:
raise SystemExit('akshare returned a truncated US list; upgrade akshare or retry') Try / catch
try:
symbols = get_us_symbols()
except ValueError as e:
if 'request error' in str(e):
time.sleep(60)
symbols = get_us_symbols()
else:
raise Prevention
- Pin/upgrade akshare deliberately — its scrapers drift with the upstream site.
- Cache the resulting symbol set to disk so downstream steps do not re-hit the source.
When it happens
Trigger: Calling get_us_symbols() when akshare's US stock-name endpoint returns a truncated table (upstream throttling, layout change breaking akshare's parser, or an old akshare version returning partial data), leaving len < 8000.
Common situations: Outdated akshare package whose scraping selectors no longer match the eastmoney page; rate limiting after repeated runs in CI; akshare API renames (ak.get_us_stock_name may itself fail on some versions) surfacing as short lists.
Related errors
AI-assisted analysis of microsoft/qlib@79633dd950 (2026-08-15).
Data as JSON: /api/errors/f281337d59786736.
Report an issue: GitHub.