ZhuLinsen/daily_stock_analysis · error · DataFetchError
[Finnhub] HTTP request failed for {symbol}: {e}
Error message
[Finnhub] HTTP request failed for {symbol}: {e} What it means
Network/HTTP failure in FinnhubFetcher._fetch_raw_data: requests.get (timeout=15) raised, raise_for_status saw a 4xx/5xx, or JSON decoding failed. The original exception is chained (__cause__) and embedded in the message, so the status code or timeout reason is visible verbatim.
Source
Thrown at data_provider/finnhub_fetcher.py:66
start_ts = int(datetime.strptime(start_date, '%Y-%m-%d').timestamp())
end_ts = int(datetime.strptime(end_date, '%Y-%m-%d').timestamp())
url = f"{_FINNHUB_BASE_URL}/stock/candle"
params = {
'symbol': symbol,
'resolution': 'D',
'from': start_ts,
'to': end_ts,
'token': self._api_key,
}
try:
self.random_sleep(0.3, 0.8)
resp = requests.get(url, params=params, timeout=15)
resp.raise_for_status()
data = resp.json()
except Exception as e:
raise DataFetchError(f"[Finnhub] HTTP request failed for {symbol}: {e}") from e
if data.get('s') != 'ok' or not data.get('c'):
raise DataFetchError(f"[Finnhub] No data returned for {symbol}")
return pd.DataFrame({
'c': data['c'],
'h': data['h'],
'l': data['l'],
'o': data['o'],
't': data['t'],
'v': data['v'],
})
def _normalize_data(self, df: pd.DataFrame, stock_code: str) -> pd.DataFrame:
if df.empty:
return df
df = df.copy()View on GitHub (pinned to 5159bd72e8)
Solutions
- Inspect the embedded {e}: 429 -> slow down / upgrade plan; 403 -> reissue the API key; timeout -> retry once, then fail over to AlphaVantage/YFinance via the manager.
- Add backoff between Finnhub calls to stay under the free-tier per-minute quota.
- Verify network egress to finnhub.io (proxy/HTTP_PROXY settings) in containers and CI.
Defensive patterns
Strategy: retry
Try / catch
try:
df = finnhub.get_daily_data(symbol, ...)
except DataFetchError as e:
msg = str(e)
if '429' in msg:
time.sleep(60); df = finnhub.get_daily_data(symbol, ...)
elif '403' in msg:
alert('Finnhub key rejected')
else:
df = manager.get_daily_data(symbol, ...) # fail over Prevention
- Stay under Finnhub free-tier quota (60 req/min) with client-side throttling.
- Set HTTP(S)_PROXY correctly in containerized runs.
- Retry once on timeout, then fail over — the manager chain already encodes this.
When it happens
Trigger: GET {FINNHUB_BASE_URL}/stock/candle with symbol/resolution/from/to/token — timeouts after 15s, 403 (invalid key / key disabled), 429 (free-tier 60 calls/min), DNS/TLS failures, or a non-JSON error page.
Common situations: Free-tier rate limit exhaustion (429) during batch US fetches; revoked API key (403); corporate proxy blocking finnhub.io; slow mobile networks hitting the 15s timeout.
Related errors
- [AlphaVantage] HTTP request failed for {symbol}: {e}
- {call_name} 调用超过 {wait_seconds:g}s,已放弃等待
- 题材新闻搜索超过 {wait_seconds:g}s,已终止请求进程
- {task_name} ranking fetch timeout after {timeout_value:g}s
- read_failed
AI-assisted analysis of ZhuLinsen/daily_stock_analysis@5159bd72e8 (2026-08-15).
Data as JSON: /api/errors/e934094dc3177541.
Report an issue: GitHub.