OpenBB-finance/OpenBB · error · ValueError
Country '{v}' is not a valid IMF country code (ISO3) or coun
Error message
Country '{v}' is not a valid IMF country code (ISO3) or country name. What it means
Error "Country '{v}' is not a valid IMF country code (ISO3) or country name." thrown in OpenBB-finance/OpenBB.
Source
Thrown at openbb_platform/providers/imf/openbb_imf/models/consumer_price_index.py:353
def validate_country(cls, c):
"""Validate country.
Accepts both ISO3 codes (e.g., "USA") and snake_case country names
(e.g., "united_states"). Converts names to ISO3 codes.
"""
result: list = []
values = c.replace(" ", "_").split(",")
for v in values:
v_upper = v.upper()
v_lower = v.lower()
# Check if it's a valid ISO3 code
if v_upper in CPI_CODE_SET:
result.append(v_upper)
# Check if it's a valid snake_case country name
elif v_lower in CPI_LABEL_TO_CODE:
result.append(CPI_LABEL_TO_CODE[v_lower])
else:
raise ValueError(
f"Country '{v}' is not a valid IMF country code (ISO3) or country name."
)
return ",".join(result)
@field_validator("expenditure", mode="before", check_fields=False)
@classmethod
def validate_expenditure(cls, v):
"""Validate expenditure."""
expenditures = v.replace(" ", "_").split(",")
new_expenditures: list[str] = []
for e in expenditures:
if (
e.lower() not in expenditure_choices
and e.upper() not in expenditure_dict_rev
):
raise ValueError(
f"Expenditure '{e}' is not a valid choice. Valid choices:\n\n{expenditure_choices}"View on GitHub (pinned to 3e071fcc2c)
Solutions
- Use a valid IMF country code (ISO3, e.g. 'USA') or a recognized country name.
- Check spelling of the country parameter.
When it happens
Trigger: Thrown at openbb_platform/providers/imf/openbb_imf/models/consumer_price_index.py:353 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/0c503cd7f9bb1b11.
Report an issue: GitHub.