OpenBB-finance/OpenBB · error · ValueError

Country {country} not found in available countries: {COUNTRY

Error message

Country {country} not found in available countries: {COUNTRY_PORTFOLIO_FILES}

What it means

Raised by get_international_portfolio_data when the normalized country name is not a key in COUNTRY_PORTFOLIO_FILES. Country is title-cased and underscores replaced with spaces before the check, so 'japan' or 'united_kingdom' are valid forms; anything else fails.

Source

Thrown at openbb_platform/providers/famafrench/openbb_famafrench/utils/helpers.py:551

        raise ValueError(
            "Please provide either an index or a country, not both at the same time."
        )
    if index:
        index = INTERNATIONAL_INDEX_PORTFOLIO_FILES.get(index)

        if not index:
            raise ValueError(
                f"Index {index} not found in available indexes: "
                + f"{INTERNATIONAL_INDEX_PORTFOLIO_FILES}"
            )
        url = (
            BASE_URL
            + INTERNATIONAL_INDEX_PORTFOLIOS_URLS["dividends" if dividends else "ex"]
        )
    if country:
        country = country.title().replace("_", " ")
        if country not in list(COUNTRY_PORTFOLIO_FILES):
            raise ValueError(
                f"Country {country} not found in available countries: "
                + f"{COUNTRY_PORTFOLIO_FILES}"
            )
        url = BASE_URL + COUNTRY_PORTFOLIOS_URLS["dividends" if dividends else "ex"]
        index = COUNTRY_PORTFOLIO_FILES[country]

    response = download_international_portfolios(url)

    with zipfile.ZipFile(BytesIO(response.content)) as f:
        filenames = f.namelist()

        if index in filenames:
            try:
                with f.open(index) as file:
                    data = file.read().decode("utf-8")
            except UnicodeDecodeError:
                # Fallback to latin-1 encoding if utf-8 fails
                with f.open(index) as file:

View on GitHub (pinned to 3e071fcc2c)

Solutions

  1. Use a full country name that title-cases to a COUNTRY_PORTFOLIO_FILES key, e.g. 'japan', 'united_kingdom', 'United States'.
  2. Check the keys of COUNTRY_PORTFOLIO_FILES in openbb_famafrench/utils/helpers.py for coverage.
  3. Note the normalization: lowercase or underscore forms are fine, but codes and abbreviations are not.

Example fix

// before
obb.economy.famafrench.international_index_returns(country='JP')

// after
obb.economy.famafrench.international_index_returns(country='japan')
Defensive patterns

Strategy: validation

Validate before calling

from openbb_famafrench.utils.helpers import COUNTRY_PORTFOLIO_FILES
name = country.title().replace('_', ' ')
if name not in COUNTRY_PORTFOLIO_FILES:
    raise ValueError(f'{country!r} not covered; choose from {list(COUNTRY_PORTFOLIO_FILES)}')

Type guard

def is_valid_ff_country(country: str) -> bool:
    from openbb_famafrench.utils.helpers import COUNTRY_PORTFOLIO_FILES
    return country.title().replace('_', ' ') in COUNTRY_PORTFOLIO_FILES

Prevention

When it happens

Trigger: Calling international portfolio returns with country='JP', 'U.K.', or any name not in COUNTRY_PORTFOLIO_FILES after title-casing and underscore-to-space normalization.

Common situations: Passing country codes ('JP', 'GB') instead of names; non-English country names; countries not covered by the Fama/French country portfolios dataset.

Related errors


AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14). Data as JSON: /api/errors/91a49819b0f34bad. Report an issue: GitHub.