{"record":{"id":"b5171af0328e0db1","repo":"OpenBB-finance/OpenBB","slug":"error-please-supply-a-2-letter-iso-country-code","errorCode":null,"errorMessage":"Error: Please supply a 2-Letter ISO Country Code -> {country}","messagePattern":"Error: Please supply a 2-Letter ISO Country Code -> (.+?)","errorType":"exception","errorClass":"OpenBBError","httpStatus":null,"severity":"error","filePath":"openbb_platform/providers/econdb/openbb_econdb/utils/main_indicators.py","lineNumber":110,"sourceCode":"async 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\n    row_is_parent = [d[\"is_parent\"] for d in row_names]  # type: ignore\n    parent_map = {d[\"code\"]: d[\"is_parent\"] for d in row_names}  # type: ignore\n    units_col = r.get(\"units_col\")  # type: ignore\n    metadata = r.get(\"footnote\")  # type: ignore","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/providers/econdb/openbb_econdb/utils/main_indicators.py#L92-L128","documentation":"Raised by the EconDB main indicators fetcher when, after 3-letter translation and the COUNTRY_MAP alias step, the country string is not exactly 2 characters. The function requires an ISO alpha-2 code to build the econdb.com URL, so any other length (a full country name, 4+ letters, or an empty string) is rejected here.","triggerScenarios":"Passing country='United States', country='DEU' that mapped to a non-2-char value, country='' (empty), or any string whose length is not 2 after the earlier mapping steps.","commonSituations":"Users passing human-readable country names instead of codes; empty string defaults leaking from upstream config; whitespace-padded inputs making len 3+.","solutions":["Pass a 2-letter ISO alpha-2 code, e.g. 'US', 'DE', 'JP'.","If you only have a country name, map it to alpha-2 yourself (e.g. pycountry) before calling.","Strip whitespace and validate len == 2 before the call.","For 3-letter codes, ensure they are valid ISO alpha-3 so they translate through THREE_LETTER_ISO_MAP."],"exampleFix":"# before\nawait get_main_indicators(country='Germany')\n\n# after\nawait get_main_indicators(country='DE')","handlingStrategy":"validation","validationCode":"def to_alpha2(country: str) -> str | None:\n    c = country.strip().upper()\n    if len(c) == 2:\n        return c\n    try:\n        import pycountry\n        return pycountry.countries.lookup(c).alpha_2\n    except LookupError:\n        return None\n\nassert to_alpha2('Germany') == 'DE'","typeGuard":"def is_alpha2(country: str) -> bool:\n    return isinstance(country, str) and len(country.strip()) == 2 and country.strip().isalpha()","tryCatchPattern":"try:\n    data = await obb.economy.main_indicators(country=country, provider='econdb')\nexcept OpenBBError as e:\n    if '2-Letter ISO Country Code' in str(e):\n        country = to_alpha2(country)  # translate and retry once\n        data = await obb.economy.main_indicators(country=country, provider='econdb')\n    else:\n        raise","preventionTips":["Never pass full country names — translate them first","Validate length-2 alpha strings at the API boundary of your own app"],"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"}