mirror of
https://github.com/TauricResearch/TradingAgents.git
synced 2026-09-19 19:25:24 +03:00
fix(data): catch http.client transport errors in StockTwits
A truncated/incomplete chunked response raises http.client exceptions (IncompleteRead/BadStatusLine) that are not OSErrors, so they bypassed the existing handler and crashed the analysis. Broaden the catch so the fetch degrades to its placeholder string like every other transport failure.
This commit is contained in:
@@ -14,11 +14,9 @@ network call succeeded.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import http.client
|
||||
import json
|
||||
import logging
|
||||
from datetime import datetime, timezone
|
||||
from typing import Optional
|
||||
from urllib.error import HTTPError, URLError
|
||||
from urllib.request import Request, urlopen
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -40,7 +38,9 @@ def fetch_stocktwits_messages(ticker: str, limit: int = 30, timeout: float = 10.
|
||||
try:
|
||||
with urlopen(req, timeout=timeout) as resp:
|
||||
data = json.loads(resp.read())
|
||||
except (HTTPError, URLError, json.JSONDecodeError, TimeoutError) as exc:
|
||||
except (OSError, http.client.HTTPException, json.JSONDecodeError) as exc:
|
||||
# OSError covers URLError/TimeoutError/connection resets; HTTPException
|
||||
# covers chunked-transfer errors (IncompleteRead/BadStatusLine, #1024).
|
||||
logger.warning("StockTwits fetch failed for %s: %s", ticker, exc)
|
||||
return f"<stocktwits unavailable: {type(exc).__name__}>"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user