{"record":{"id":"e26b94aa694e888d","repo":"OpenBB-finance/OpenBB","slug":"country-code-is-not-supported-by-imf-port-watch","errorCode":null,"errorMessage":"Country code is not supported by IMF Port Watch.","messagePattern":"Country code is not supported by IMF Port Watch\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"openbb_platform/providers/imf/openbb_imf/utils/port_watch_helpers.py","lineNumber":57,"sourceCode":"\ndef map_port_country_code(country_code: str) -> str:\n    \"\"\"Map the 3-letter country code to the full country name.\n\n    Parameters\n    ----------\n    country_code : str\n        The 3-letter ISO country code (e.g., \"USA\" for the United States).\n\n    Returns\n    -------\n    str\n        The full country name, without accents, corresponding to the provided country code.\n    \"\"\"\n    cc = country_code.upper()\n    countries = list_countries()\n    code_to_country = {country[\"value\"]: country[\"label\"] for country in countries}\n    if cc not in code_to_country:\n        raise ValueError(\"Country code is not supported by IMF Port Watch.\")\n\n    return code_to_country.get(cc, cc)\n\n\ndef get_port_ids_by_country(country_code: str) -> str:\n    \"\"\"Get all port IDs for a specific country. The country code should be a 3-letter ISO code.\n\n    Parameters\n    ----------\n    country_code : str\n        The 3-letter ISO country code (e.g., \"USA\" for the United States).\n\n    Returns\n    -------\n    str\n        A list of port IDs as a comma-separated string.\n    \"\"\"\n    ports = get_ports()","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/providers/imf/openbb_imf/utils/port_watch_helpers.py#L39-L75","documentation":"Raised by the Port Watch country-code resolver: the uppercased country code is not among the {value: label} pairs returned by list_countries(), so the IMF Port Watch API has no matching country. It is an input-validation ValueError occurring before any HTTP request.","triggerScenarios":"Passing a 2-letter code ('US') instead of the required 3-letter ISO code ('USA'); non-ISO or retired codes ('ZAR'); codes of territories Port Watch does not cover; codes with whitespace or punctuation.","commonSituations":"Users habitually typing ISO 3166-1 alpha-2 codes, forwarding World Bank alpha-2 codes into a Port Watch call, or passing a currency code by mistake.","solutions":["Use the 3-letter ISO 3166-1 alpha-3 code (e.g. 'USA', 'CHN', 'DEU').","If you hold alpha-2 codes, map them to alpha-3 (e.g. via pycountry) before calling.","Validate against list_countries() values up front and show the supported set on failure."],"exampleFix":"# before\nname = get_country_name_from_code('US')\n\n# after\nimport pycountry\nc = pycountry.countries.get(alpha_2='US')\nname = get_country_name_from_code(c.alpha_3)  # 'USA'","handlingStrategy":"validation","validationCode":"from openbb_imf.utils.port_watch_helpers import list_countries\nSUPPORTED = {c['value'] for c in list_countries()}\n\ndef normalize_country(code: str) -> str:\n    cc = code.strip().upper()\n    if len(cc) == 2:\n        import pycountry\n        cc = pycountry.countries.get(alpha_2=cc).alpha_3\n    if cc not in SUPPORTED:\n        raise ValueError(f'{code!r} unsupported; use 3-letter ISO codes')\n    return cc","typeGuard":"def is_supported_country_code(code: object) -> bool:\n    if not isinstance(code, str) or len(code.strip()) != 3:\n        return False\n    return code.strip().upper() in {c['value'] for c in list_countries()}","tryCatchPattern":"try:\n    name = get_country_name_from_code(code)\nexcept ValueError as e:\n    if 'not supported' in str(e):\n        raise InvalidInput('Provide a 3-letter ISO 3166-1 alpha-3 code') from e\n    raise","preventionTips":["Standardize on alpha-3 codes at your API boundary.","Cache the supported-code set once per session instead of refetching per validation."],"tags":["imf","port-watch","validation","country-code","iso"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}