OpenBB-finance/OpenBB · error · ValueError
Country must be a string or list of strings. Got {type(v)}
Error message
Country must be a string or list of strings. Got {type(v)} What it means
Error "Country must be a string or list of strings. Got {type(v)}" thrown in OpenBB-finance/OpenBB.
Source
Thrown at openbb_platform/providers/government_us/openbb_government_us/models/commodity_psd_data.py:276
return attributes
@field_validator("country", mode="before", check_fields=False)
@classmethod
def _validate_country(cls, v):
"""Validate country."""
if not v:
return None
if v and isinstance(v, list) and not v[0]:
return None
countries = v
if isinstance(countries, str):
countries = [countries] if "," not in countries else countries.split(",")
if not isinstance(countries, list):
raise ValueError(
f"Country must be a string or list of strings. Got {type(v)}"
)
if isinstance(countries, list) and len(countries) == 1 and "," in countries[0]:
countries = countries[0].split(",")
invalid_countries = [
country
for country in countries
if country
and country not in COUNTRY_CHOICES.values()
and country not in COUNTRY_CHOICES
]
if invalid_countries:
raise ValueError(
f"Invalid country code(s) '{', '.join(invalid_countries)}'. Valid country codes are: "
+ ", ".join(View on GitHub (pinned to 3e071fcc2c)
Solutions
- Pass the country as a string or a list of strings.
- Remove any non-string items from the country list.
When it happens
Trigger: Thrown at openbb_platform/providers/government_us/openbb_government_us/models/commodity_psd_data.py:276 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/a112865a1b583912.
Report an issue: GitHub.