ZhuLinsen/daily_stock_analysis · error · DataFetchError
[AlphaVantage] API error for {symbol}: {data['Error Message'
Error message
[AlphaVantage] API error for {symbol}: {data['Error Message']} What it means
A DataFetchError raised by AlphaVantageFetcher._fetch_raw_data when the JSON response contains an 'Error Message' key. AlphaVantage uses this field (with HTTP 200) for hard API-level failures — most commonly an invalid or unknown symbol, but also invalid function parameters or a malformed apikey.
Source
Thrown at data_provider/alphavantage_fetcher.py:66
params = {
'function': 'TIME_SERIES_DAILY',
'symbol': symbol,
'outputsize': 'compact',
'apikey': self._api_key,
}
try:
self.random_sleep(0.5, 1.5)
resp = requests.get(_AV_BASE_URL, params=params, timeout=30)
resp.raise_for_status()
data = resp.json()
except Exception as e:
raise DataFetchError(f"[AlphaVantage] HTTP request failed for {symbol}: {e}") from e
if 'Note' in data:
raise DataFetchError(f"[AlphaVantage] Rate limited: {data['Note']}")
if 'Error Message' in data:
raise DataFetchError(f"[AlphaVantage] API error for {symbol}: {data['Error Message']}")
ts_key = 'Time Series (Daily)'
if ts_key not in data or not data[ts_key]:
raise DataFetchError(f"[AlphaVantage] No time series data for {symbol}")
rows = []
start = datetime.strptime(start_date, '%Y-%m-%d').date()
end = datetime.strptime(end_date, '%Y-%m-%d').date()
for date_str, values in data[ts_key].items():
row_date = datetime.strptime(date_str, '%Y-%m-%d').date()
if start <= row_date <= end:
rows.append({
'date': date_str,
'1. open': float(values.get('1. open', 0)),
'2. high': float(values.get('2. high', 0)),
'3. low': float(values.get('3. low', 0)),
'4. close': float(values.get('4. close', 0)),
'5. volume': float(values.get('5. volume', 0)),View on GitHub (pinned to 5159bd72e8)
Solutions
- Read the embedded Error Message — AV states the exact reason ('Invalid API call ... symbol').
- Validate the symbol exists on AlphaVantage (test with the demo IBM call pattern) before adding it to batch jobs.
- Strip whitespace from the API key and re-copy it from the AV dashboard.
- Treat as permanent for that symbol: exclude it from AV routing and use a market-appropriate source.
Example fix
# before
syms = ['AAPL', 'APPL', 'BRK.B'] # typos/unsupported
for s in syms:
df = av_fetcher.fetch(s, start, end) # dies on 'APPL'
# after
for s in syms:
try:
df = av_fetcher.fetch(s, start, end)
except DataFetchError as e:
if 'API error' in str(e):
logger.warning('skip invalid symbol %s: %s', s, e)
continue Defensive patterns
Strategy: try-catch
Validate before calling
import requests, os
r = requests.get('https://www.alphavantage.co/query', params={
'function': 'TIME_SERIES_DAILY', 'symbol': sym,
'apikey': os.environ['ALPHAVANTAGE_API_KEY']}, timeout=10)
data = r.json()
if 'Error Message' in data:
raise ValueError(f'symbol {sym} rejected by AlphaVantage: {data["Error Message"]}') Try / catch
try:
df = av_fetcher.fetch(sym, start, end)
except DataFetchError as e:
if 'API error' in str(e):
logger.warning('permanently skipping invalid symbol %s: %s', sym, e)
continue
raise Prevention
- Validate symbols against AV once (demo call) before adding them to recurring watchlists.
- Strip whitespace/newlines from API keys when configuring them.
- Classify 'API error' as permanent-for-symbol: exclude, don't retry.
When it happens
Trigger: Requesting a symbol AV does not recognize (typo like 'APPL', delisted ticker, or a non-US symbol that slipped past the is_us_stock_code guard); passing an invalid parameter; a truncated/invalid API key that passes the not-empty check but is rejected by the service.
Common situations: Watchlists with stale/delisted tickers; symbols with dots or share classes ('BRK.B') that AV rejects; copy-pasted key with whitespace; ADR/OTC tickers unsupported by TIME_SERIES_DAILY.
Related errors
- [AlphaVantage] {stock_code} is not a US stock
- Backend executable not found: ${backendPath}
- Invalid share image record ID
- Desktop backend URL is unavailable
- Desktop backend origin is invalid
AI-assisted analysis of ZhuLinsen/daily_stock_analysis@5159bd72e8 (2026-08-15).
Data as JSON: /api/errors/c2fd0b438a693d4e.
Report an issue: GitHub.