OpenBB-finance/OpenBB · error · OpenBBError

Error: Invalid country code -> {country}

Error message

Error: Invalid country code -> {country}

What it means

Thrown by the EconDB 'main indicators' fetcher when a 3-letter ISO country code cannot be translated. The function looks the code up in THREE_LETTER_ISO_MAP (uppercased); a miss returns None and this OpenBBError is raised immediately. It means the caller passed something three characters long that is not a recognized ISO-3166 alpha-3 code (or a code EconDB's map does not carry).

Source

Thrown at openbb_platform/providers/econdb/openbb_econdb/utils/main_indicators.py:106

    return response


async def get_main_indicators(  # pylint: disable=R0913,R0914,R0915,R0917
    country: str = "US",
    start_date: str = (datetime.now() - timedelta(weeks=52 * 3)).strftime("%Y-%m-%d"),
    end_date: str = datetime.now().strftime("%Y-%m-%d"),
    frequency: Literal["annual", "quarter", "month"] = "quarter",
    transform: Literal["tpop", "toya", "level", "tusd", None] = "toya",
    use_cache: bool = True,
) -> list[dict]:
    """Get the main indicators for a given country."""
    freq = trends_freq_dict.get(frequency)
    transform = trends_transform_dict.get(transform)  # type: ignore
    if len(country) == 3:
        country = THREE_LETTER_ISO_MAP.get(country.upper())  # type: ignore
        if not country:
            raise OpenBBError(f"Error: Invalid country code -> {country}")
    if country in COUNTRY_MAP:
        country = COUNTRY_MAP.get(country)  # type: ignore
    if len(country) != 2:
        raise OpenBBError(
            f"Error: Please supply a 2-Letter ISO Country Code -> {country}"
        )
    if country not in COUNTRY_MAP.values():
        raise OpenBBError(f"Error: Invalid country code -> {country}")
    parents_url = (
        "https://www.econdb.com/trends/country_forecast/"
        + f"?country={country}&freq={freq}&transform={transform}"
        + f"&dateStart={start_date}&dateEnd={end_date}"
    )
    r = await fetch_data(parents_url, use_cache)
    row_names = r.get("row_names")  # type: ignore
    row_symbols = []
    row_is_parent = []
    row_symbols = [d["code"] for d in row_names]  # type: ignore

View on GitHub (pinned to 3e071fcc2c)

Solutions

  1. Supply a valid ISO-3166 alpha-3 code (e.g. 'USA', 'FRA', 'JPN') or, better, a 2-letter alpha-2 code.
  2. Verify the code exists in openbb_econdb.utils.helpers.THREE_LETTER_ISO_MAP before calling.
  3. Trim and uppercase the input before passing: country.strip().upper().
  4. If a legitimate ISO-3 code is missing from the map, pass its alpha-2 equivalent and file an issue to update the map.

Example fix

# before
res = await obb.economy.main_indicators(country='USS', provider='econdb')

# after
res = await obb.economy.main_indicators(country='USA', provider='econdb')  # or 'US'
Defensive patterns

Strategy: validation

Validate before calling

from openbb_econdb.utils.helpers import THREE_LETTER_ISO_MAP

def valid_country_input(country: str) -> bool:
    c = country.strip().upper()
    if len(c) == 3:
        return c in THREE_LETTER_ISO_MAP
    return len(c) == 2

Try / catch

try:
    data = await obb.economy.main_indicators(country=country, provider='econdb')
except OpenBBError as e:
    if 'Invalid country code' in str(e):
        logger.warning('Unsupported ISO-3 code: %s', country)
    raise

Prevention

When it happens

Trigger: Calling economy/econdb main-indicators with country='USA' works, but country='ZZZ', a typo like 'USS', or a non-ISO 3-char string ('U.S', 'us1') makes THREE_LETTER_ISO_MAP.get() return None and hit this raise.

Common situations: Users pasting country names abbreviated to 3 letters that are not ISO codes; maps that lag ISO updates for new/renamed countries; case-sensitive inputs where the code was expected pre-uppercase but contains digits or punctuation.

Related errors


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