OpenBB-finance/OpenBB · error · OpenBBError
Error: Please supply a 2-Letter ISO Country Code -> {country
Error message
Error: Please supply a 2-Letter ISO Country Code -> {country} What it means
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.
Source
Thrown at openbb_platform/providers/econdb/openbb_econdb/utils/main_indicators.py:110
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
row_is_parent = [d["is_parent"] for d in row_names] # type: ignore
parent_map = {d["code"]: d["is_parent"] for d in row_names} # type: ignore
units_col = r.get("units_col") # type: ignore
metadata = r.get("footnote") # type: ignoreView on GitHub (pinned to 3e071fcc2c)
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.
Example fix
# before await get_main_indicators(country='Germany') # after await get_main_indicators(country='DE')
Defensive patterns
Strategy: validation
Validate before calling
def to_alpha2(country: str) -> str | None:
c = country.strip().upper()
if len(c) == 2:
return c
try:
import pycountry
return pycountry.countries.lookup(c).alpha_2
except LookupError:
return None
assert to_alpha2('Germany') == 'DE' Type guard
def is_alpha2(country: str) -> bool:
return isinstance(country, str) and len(country.strip()) == 2 and country.strip().isalpha() Try / catch
try:
data = await obb.economy.main_indicators(country=country, provider='econdb')
except OpenBBError as e:
if '2-Letter ISO Country Code' in str(e):
country = to_alpha2(country) # translate and retry once
data = await obb.economy.main_indicators(country=country, provider='econdb')
else:
raise Prevention
- Never pass full country names — translate them first
- Validate length-2 alpha strings at the API boundary of your own app
When it happens
Trigger: 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.
Common situations: Users passing human-readable country names instead of codes; empty string defaults leaking from upstream config; whitespace-padded inputs making len 3+.
Related errors
- Error: Invalid country code -> {country}
- No valid countries were supplied.
- At least one extension type must be selected.
- Results not found.
- Please install polars: `pip install polars pyarrow` to use
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/b5171af0328e0db1.
Report an issue: GitHub.