OpenBB-finance/OpenBB · error · HTTPException

Incorrect email or password

Error message

Incorrect email or password

What it means

Raised by the CPI query-params validator for the `expenditure` field when a token (spaces to underscores, split on commas) is neither in the lowercase `expenditure_choices` set nor in `expenditure_dict_rev` (keys/uppercase forms). The message embeds the full valid-choices text, so the error itself is the documentation for what is accepted. Fails at model construction, before any IMF request.

Source

Thrown at openbb_platform/core/openbb_core/api/auth/user.py:39

        password = Env().API_PASSWORD

        is_correct_username = False
        is_correct_password = False

        if username is not None and password is not None:
            current_username_bytes = credentials.username.encode("utf8")
            correct_username_bytes = username.encode("utf8")
            is_correct_username = secrets.compare_digest(
                current_username_bytes, correct_username_bytes
            )
            current_password_bytes = credentials.password.encode("utf8")
            correct_password_bytes = password.encode("utf8")
            is_correct_password = secrets.compare_digest(
                current_password_bytes, correct_password_bytes
            )

        if not (is_correct_username and is_correct_password):
            raise HTTPException(
                status_code=status.HTTP_401_UNAUTHORIZED,
                detail="Incorrect email or password",
                headers={"WWW-Authenticate": "Basic"},
            )


async def get_user_service() -> UserService:
    """Get user service."""
    return UserService()


async def get_user_settings(
    _: Annotated[None, Depends(authenticate_user)],
    user_service: Annotated[UserService, Depends(get_user_service)],
) -> UserSettings:
    """Get user settings."""
    return user_service.read_from_file()

View on GitHub (pinned to 3e071fcc2c)

Solutions

  1. Read the `{expenditure_choices}` list embedded in the error message and pass one of those exact values.
  2. Programmatically: `from openbb_imf.models.consumer_price_index import expenditure_choices` and validate/select from it.
  3. Use lowercase snake_case tokens; the validator checks lowercase membership first.
  4. Upgrade openbb-imf if the category was renamed in a newer provider version.

Example fix

# before
res = obb.economy.cpi(provider='imf', country='USA', expenditure='food')

# after
res = obb.economy.cpi(provider='imf', country='USA', expenditure='food_and_non_alcoholic_beverages')
Defensive patterns

Strategy: validation

Validate before calling

from openbb_imf.models.consumer_price_index import expenditure_choices

def validate_cpi_expenditure(raw: str) -> str:
    tokens = [e.replace(' ', '_').lower() for e in raw.split(',')]
    bad = [e for e in tokens if e not in expenditure_choices]
    if bad:
        raise ValueError(f'Invalid expenditure(s) {bad}; valid: {sorted(expenditure_choices)}')
    return ','.join(tokens)

Type guard

from openbb_imf.models.consumer_price_index import expenditure_choices

def is_valid_expenditure(e: str) -> bool:
    return e.replace(' ', '_').lower() in expenditure_choices

Prevention

When it happens

Trigger: Passing `expenditure='food'` when the valid choices are COICOP-style categories (e.g. 'food_and_non_alcoholic_beverages'), or a typo like `expenditure='alltems'`, or a comma list containing one invalid item.

Common situations: Guessing COICOP category names instead of copying them from the error message or docs; version drift where upstream renamed expenditure categories; UI dropdowns fed from a stale choices list.

Related errors


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