{"record":{"id":"64f8a34b9ae1ed15","repo":"OpenBB-finance/OpenBB","slug":"error-invalid-country-code-country","errorCode":null,"errorMessage":"Error: Invalid country code -> {country}","messagePattern":"Error: Invalid country code -> (.+?)","errorType":"exception","errorClass":"OpenBBError","httpStatus":null,"severity":"error","filePath":"openbb_platform/providers/econdb/openbb_econdb/utils/main_indicators.py","lineNumber":106,"sourceCode":"\n    return response\n\n\nasync def get_main_indicators(  # pylint: disable=R0913,R0914,R0915,R0917\n    country: str = \"US\",\n    start_date: str = (datetime.now() - timedelta(weeks=52 * 3)).strftime(\"%Y-%m-%d\"),\n    end_date: str = datetime.now().strftime(\"%Y-%m-%d\"),\n    frequency: Literal[\"annual\", \"quarter\", \"month\"] = \"quarter\",\n    transform: Literal[\"tpop\", \"toya\", \"level\", \"tusd\", None] = \"toya\",\n    use_cache: bool = True,\n) -> list[dict]:\n    \"\"\"Get the main indicators for a given country.\"\"\"\n    freq = trends_freq_dict.get(frequency)\n    transform = trends_transform_dict.get(transform)  # type: ignore\n    if len(country) == 3:\n        country = THREE_LETTER_ISO_MAP.get(country.upper())  # type: ignore\n        if not country:\n            raise OpenBBError(f\"Error: Invalid country code -> {country}\")\n    if country in COUNTRY_MAP:\n        country = COUNTRY_MAP.get(country)  # type: ignore\n    if len(country) != 2:\n        raise OpenBBError(\n            f\"Error: Please supply a 2-Letter ISO Country Code -> {country}\"\n        )\n    if country not in COUNTRY_MAP.values():\n        raise OpenBBError(f\"Error: Invalid country code -> {country}\")\n    parents_url = (\n        \"https://www.econdb.com/trends/country_forecast/\"\n        + f\"?country={country}&freq={freq}&transform={transform}\"\n        + f\"&dateStart={start_date}&dateEnd={end_date}\"\n    )\n    r = await fetch_data(parents_url, use_cache)\n    row_names = r.get(\"row_names\")  # type: ignore\n    row_symbols = []\n    row_is_parent = []\n    row_symbols = [d[\"code\"] for d in row_names]  # type: ignore","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/providers/econdb/openbb_econdb/utils/main_indicators.py#L88-L124","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Supply a valid ISO-3166 alpha-3 code (e.g. 'USA', 'FRA', 'JPN') or, better, a 2-letter alpha-2 code.","Verify the code exists in openbb_econdb.utils.helpers.THREE_LETTER_ISO_MAP before calling.","Trim and uppercase the input before passing: country.strip().upper().","If a legitimate ISO-3 code is missing from the map, pass its alpha-2 equivalent and file an issue to update the map."],"exampleFix":"# before\nres = await obb.economy.main_indicators(country='USS', provider='econdb')\n\n# after\nres = await obb.economy.main_indicators(country='USA', provider='econdb')  # or 'US'","handlingStrategy":"validation","validationCode":"from openbb_econdb.utils.helpers import THREE_LETTER_ISO_MAP\n\ndef valid_country_input(country: str) -> bool:\n    c = country.strip().upper()\n    if len(c) == 3:\n        return c in THREE_LETTER_ISO_MAP\n    return len(c) == 2","typeGuard":null,"tryCatchPattern":"try:\n    data = await obb.economy.main_indicators(country=country, provider='econdb')\nexcept OpenBBError as e:\n    if 'Invalid country code' in str(e):\n        logger.warning('Unsupported ISO-3 code: %s', country)\n    raise","preventionTips":["Normalize inputs to uppercase, stripped strings before calling","Prefer 2-letter ISO alpha-2 codes","Keep a whitelist of supported countries sourced from COUNTRY_MAP"],"tags":["econdb","validation","country-code","iso-3166"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}