python-poetry/poetry · error · ValueError

Expected only one argument (token), got {len(values)}

Error message

Expected only one argument (token), got {len(values)}

What it means

Raises ValueError in ConfigCommand.handle() when setting a PyPI token with a number of values other than exactly 1. A token is a single string; providing zero or 2+ values is invalid. The check at line 300-303 fires inside the pypi-token branch of the auth-handling section.

Source

Thrown at src/poetry/console/commands/config.py:301

            if m.group(1) == "http-basic":
                if len(values) == 1:
                    username = values[0]
                    # Only username, so we prompt for password
                    password = self.secret("Password:")
                    assert isinstance(password, str)
                elif len(values) != 2:
                    raise ValueError(
                        "Expected one or two arguments "
                        f"(username, password), got {len(values)}"
                    )
                else:
                    username = values[0]
                    password = values[1]

                password_manager.set_http_password(m.group(2), username, password)
            elif m.group(1) == "pypi-token":
                if len(values) != 1:
                    raise ValueError(
                        f"Expected only one argument (token), got {len(values)}"
                    )

                token = values[0]

                password_manager.set_pypi_token(m.group(2), token)

            return 0

        # handle certs
        m = re.match(r"certificates\.(.+)\.(cert|client-cert)$", self.argument("key"))
        if m:
            repository = m.group(1)
            key = m.group(2)

            if self.option("unset"):
                config.auth_config_source.remove_property(
                    ["certificates", repository, key]

View on GitHub (pinned to 92b74dcfe3)

Solutions

  1. Provide exactly one token string: `poetry config pypi-token.pypi pypi-AgEIcHl...`.

Example fix

# before (error)
poetry config pypi-token.pypi token-one token-two
# after
poetry config pypi-token.pypi pypi-AgEIcHl...
Defensive patterns

Strategy: validation

Validate before calling

def validate_pypi_token(values: list[str]) -> None:
    if len(values) != 1:
        raise ValueError(f"Expected exactly 1 token argument, got {len(values)}")

Type guard

def is_valid_pypi_token(values: list[str]) -> bool:
    return len(values) == 1

Prevention

When it happens

Trigger: Running `poetry config pypi-token.pypi token1 token2` (2 values) — len(values) != 1. Note: zero values would hit the LIST_PROHIBITED_SETTINGS check (error 12) first.

Common situations: User passes multiple tokens by mistake, or includes extra arguments after the token value.

Related errors


AI-assisted analysis of python-poetry/poetry@92b74dcfe3 (2026-08-04). Data as JSON: /data/errors/c62b73b597e81c27.json. Report an issue: GitHub.