OpenBB-finance/OpenBB · error · OpenBBError
Invalid JSON response from ECB
Error message
Invalid JSON response from ECB
What it means
Raised in the ECB shared helper (ecb_helpers.py) when amake_request against https://data.ecb.europa.eu/data-detail-api/{series_id} succeeds at the HTTP level but the body is not valid JSON — json.JSONDecodeError is caught and re-wrapped as OpenBBError('Invalid JSON response from ECB').
Source
Thrown at openbb_platform/providers/ecb/openbb_ecb/utils/ecb_helpers.py:33
"""
# pylint: disable=import-outside-toplevel
import json # noqa
from openbb_core.app.model.abstract.error import OpenBBError # noqa
from openbb_core.provider.utils.helpers import amake_request # noqa
start_date = start_date.replace("-", "")
end_date = end_date.replace("-", "")
url = f"https://data.ecb.europa.eu/data-detail-api/{series_id}"
data: list = [] # type: ignore
try:
data = await amake_request( # type: ignore
url=url,
params={"startPeriod": start_date, "endPeriod": end_date},
)
except KeyboardInterrupt as interrupt:
raise interrupt
except json.JSONDecodeError as exc:
raise OpenBBError("Invalid JSON response from ECB") from exc
if start_date:
data = [item for item in data if item["PERIOD"][0] >= start_date]
if end_date:
data = [item for item in data if item["PERIOD"][0] <= end_date]
return data
View on GitHub (pinned to 3e071fcc2c)
Solutions
- Retry with backoff — transient truncation/HTML error pages usually resolve.
- curl the same URL with the startPeriod/endPeriod params and inspect Content-Type/body to confirm what ECB is returning.
- Bypass corporate proxy or configure HTTPS_PROXY properly if a TLS-intercepting proxy is mangling bodies.
- Update the openbb-ecb provider in case the endpoint changed and now returns a different error contract.
Example fix
# before
res = obb.fixedincome.government_yield_curve(provider="ecb")
# after
import time
from openbb_core.provider.utils.errors import OpenBBError
for attempt in range(3):
try:
res = obb.fixedincome.government_yield_curve(provider="ecb", use_cache=False)
break
except OpenBBError as e:
if "Invalid JSON" in str(e) and attempt < 2:
time.sleep(2 ** attempt)
continue
raise Defensive patterns
Strategy: retry
Validate before calling
import requests
def ecb_api_returns_json(series_id: str) -> bool:
r = requests.get(f"https://data.ecb.europa.eu/data-detail-api/{series_id}", timeout=15)
return "json" in r.headers.get("content-type", "") and r.text.lstrip()[:1] in "[{" Try / catch
import time
from openbb_core.provider.utils.errors import OpenBBError
for attempt in range(3):
try:
res = fetch_ecb(series_id)
break
except OpenBBError as e:
if "Invalid JSON" in str(e) and attempt < 2:
time.sleep(2 ** attempt)
continue
raise Prevention
- Retry on JSONDecodeError — ECB serves HTML error pages transiently.
- Check content-type of raw responses when behind TLS-inspecting proxies.
- Cache valid responses so retries don't re-hit a flaky edge.
When it happens
Trigger: ECB serves an HTML error/maintenance page or truncated body where the client expects JSON; a proxy or captive portal injects HTML; content-encoding corruption. Any ECB model that uses this helper (yield curve, balance of payments, etc.) can surface it.
Common situations: ECB portal incidents or CDN edge errors returning HTML 200s; corporate TLS-inspecting proxies rewriting responses; flaky mobile/high-latency networks truncating chunked responses.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Error fetching data: {e}
- Failed to fetch data from ECB. -> Status Code: {response.sta
- Unexpected response format when fetching constraints {datafl
- Failed to parse XML response: {url} -> {e}
- Method must be GET or POST
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/a2ea89995ac71605.
Report an issue: GitHub.