{"record":{"id":"a2ea89995ac71605","repo":"OpenBB-finance/OpenBB","slug":"invalid-json-response-from-ecb","errorCode":null,"errorMessage":"Invalid JSON response from ECB","messagePattern":"Invalid JSON response from ECB","errorType":"exception","errorClass":"OpenBBError","httpStatus":null,"severity":"error","filePath":"openbb_platform/providers/ecb/openbb_ecb/utils/ecb_helpers.py","lineNumber":33,"sourceCode":"    \"\"\"\n    # pylint: disable=import-outside-toplevel\n    import json  # noqa\n    from openbb_core.app.model.abstract.error import OpenBBError  # noqa\n    from openbb_core.provider.utils.helpers import amake_request  # noqa\n\n    start_date = start_date.replace(\"-\", \"\")\n    end_date = end_date.replace(\"-\", \"\")\n    url = f\"https://data.ecb.europa.eu/data-detail-api/{series_id}\"\n    data: list = []  # type: ignore\n    try:\n        data = await amake_request(  # type: ignore\n            url=url,\n            params={\"startPeriod\": start_date, \"endPeriod\": end_date},\n        )\n    except KeyboardInterrupt as interrupt:\n        raise interrupt\n    except json.JSONDecodeError as exc:\n        raise OpenBBError(\"Invalid JSON response from ECB\") from exc\n\n    if start_date:\n        data = [item for item in data if item[\"PERIOD\"][0] >= start_date]\n    if end_date:\n        data = [item for item in data if item[\"PERIOD\"][0] <= end_date]\n\n    return data\n","sourceCodeStart":15,"sourceCodeEnd":41,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/providers/ecb/openbb_ecb/utils/ecb_helpers.py#L15-L41","documentation":"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').","triggerScenarios":"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.","commonSituations":"ECB portal incidents or CDN edge errors returning HTML 200s; corporate TLS-inspecting proxies rewriting responses; flaky mobile/high-latency networks truncating chunked responses.","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."],"exampleFix":"# before\nres = obb.fixedincome.government_yield_curve(provider=\"ecb\")\n\n# after\nimport time\nfrom openbb_core.provider.utils.errors import OpenBBError\nfor attempt in range(3):\n    try:\n        res = obb.fixedincome.government_yield_curve(provider=\"ecb\", use_cache=False)\n        break\n    except OpenBBError as e:\n        if \"Invalid JSON\" in str(e) and attempt < 2:\n            time.sleep(2 ** attempt)\n            continue\n        raise","handlingStrategy":"retry","validationCode":"import requests\n\ndef ecb_api_returns_json(series_id: str) -> bool:\n    r = requests.get(f\"https://data.ecb.europa.eu/data-detail-api/{series_id}\", timeout=15)\n    return \"json\" in r.headers.get(\"content-type\", \"\") and r.text.lstrip()[:1] in \"[{\"","typeGuard":null,"tryCatchPattern":"import time\nfrom openbb_core.provider.utils.errors import OpenBBError\nfor attempt in range(3):\n    try:\n        res = fetch_ecb(series_id)\n        break\n    except OpenBBError as e:\n        if \"Invalid JSON\" in str(e) and attempt < 2:\n            time.sleep(2 ** attempt)\n            continue\n        raise","preventionTips":["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."],"tags":["ecb","json","network","proxy","api-change"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}