OpenBB-finance/OpenBB · error · ValueError

Invalid country code(s) '{invalid_countries}'. Valid country

Error message

Invalid country code(s) '{invalid_countries}'. Valid country codes are: {valid_country_codes}

What it means

Error "Invalid country code(s) '{invalid_countries}'. Valid country codes are: {valid_country_codes}" thrown in OpenBB-finance/OpenBB.

Source

Thrown at openbb_platform/providers/government_us/openbb_government_us/models/commodity_psd_data.py:292

        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(
                    sorted(list(COUNTRY_CHOICES)),
                )
            )

        return v

    @field_validator("start_year", mode="before", check_fields=False)
    @classmethod
    def _validate_start_year(cls, v):
        """Validate start_year."""
        if v and v < 1960:
            raise ValueError("Earliest possible year is 1960.")
        return v

    @model_validator(mode="after")
    def _validate_model(self):

View on GitHub (pinned to 3e071fcc2c)

Solutions

  1. Choose country codes from the listed valid country codes.
  2. Use the correct ISO-style codes expected by the PSD dataset.

When it happens

Trigger: Thrown at openbb_platform/providers/government_us/openbb_government_us/models/commodity_psd_data.py:292 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/5143539fa558d92d. Report an issue: GitHub.