OpenBB-finance/OpenBB · error · OpenBBError

e

Error message

e

What it means

Thrown by EconDbExportDestinationsFetcher.aextract_data when the request to the EconDB 'top-trade-items' widget URL fails with an httpx ContentTypeError (the server replied with a non-JSON body, e.g. an HTML error/block page) and only a single country was requested. With one country there is nothing to fall back on, so the raw exception is wrapped in OpenBBError and re-raised. With multiple countries the failure is instead collected as a per-country message.

Source

Thrown at openbb_platform/providers/econdb/openbb_econdb/models/export_destinations.py:84

        MAP_COUNTRY = {v: k for k, v in COUNTRY_MAP.items()}

        async def get_one_country(c):
            """Get data for one country."""
            c = c.upper() if len(c) == 2 else c.lower()
            if len(c) != 2:
                c = COUNTRY_MAP.get(c, c)
                if len(c) != 2 or c.upper() not in MAP_COUNTRY:
                    messages.append(f"Invalid country code -> {c}")
                    return

            URL = f"https://www.econdb.com/widgets/top-trade-items/data/?country={c.upper()}&split_by=country"
            result: list = []
            row: dict = {}
            try:
                res = await amake_request(URL)
            except ContentTypeError as e:
                if len(countries) == 1:
                    raise OpenBBError(e) from e
                messages.append(f"No data available for the country -> {c}")
                return

            plots = res.get("plots", [])  # type: ignore
            data = plots[0].pop("data", []) if plots else []
            meta = plots[0] if plots else {}

            if not data or (len(data) == 1 and data[0].get("Value million USD") == 0):
                messages.append(f"No data available for the country -> {c}")
                return

            origin_country = MAP_COUNTRY.get(c, c)

            for item in data:
                row = {
                    "origin_country": origin_country.replace("_", " ").title(),
                    **item,
                    "units": (

View on GitHub (pinned to 3e071fcc2c)

Solutions

  1. Retry after a short delay — transient rate-limit/Cloudflare HTML responses are the most common cause.
  2. Confirm the widget URL still returns JSON in a browser/curl: https://www.econdb.com/widgets/top-trade-items/data/?country=PT&split_by=country.
  3. Pass multiple countries (country='portugal,spain') so a single-country failure degrades to a warning message instead of an exception.
  4. If the endpoint now returns HTML permanently, the widget API changed — pin/update the openbb-econdb provider package or open an issue.

Example fix

# before
obb.economy.export_destinations(provider='econdb', country='pt')

# after - multiple countries degrade gracefully instead of raising
obb.economy.export_destinations(provider='econdb', country='pt,es')
Defensive patterns

Strategy: try-catch

Validate before calling

from openbb_econdb.utils.helpers import COUNTRY_MAP
countries = ['pt']
map_country = {v: k for k, v in COUNTRY_MAP.items()}
assert all(len(c) == 2 and c.upper() in map_country for c in countries), 'use valid 2-letter ISO codes'

Type guard

def is_valid_iso2(code: str, map_country: dict[str, str]) -> bool:
    return len(code) == 2 and code.upper() in map_country

Try / catch

from openbb_core.app.model.obbject import OpenBBError
try:
    res = await obb.economy.export_destinations(provider='econdb', country='pt').to_df() if False else None
except OpenBBError as e:
    if 'ContentTypeError' in str(e):
        logger.warning('EconDB widget returned non-JSON; retrying later')
        raise

Prevention

When it happens

Trigger: Calling economy.export_destinations with a single country (e.g. country='portugal') while www.econdb.com/widgets/top-trade-items/data/ returns HTML instead of JSON — rate limiting, Cloudflare interstitial, or a removed widget endpoint.

Common situations: Running repeated scripted calls that trip rate limits; corporate proxies returning HTML error pages; EconDB changing the widget API; querying from a flagged IP.

Related errors


AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14). Data as JSON: /api/errors/2d91ca880de5e022. Report an issue: GitHub.