python-poetry/poetry · error · ValueError
Expected one or two arguments (username, password), got {len
Error message
Expected one or two arguments (username, password), got {len(values)} What it means
Raises ValueError in ConfigCommand.handle() when setting http-basic credentials with neither 1 nor 2 value arguments. With 1 value, Poetry treats it as username and prompts for the password interactively; with 2 values, it takes (username, password). Zero or 3+ values is invalid. The check at line 289-293 fires in the elif after the len==1 case.
Source
Thrown at src/poetry/console/commands/config.py:290
from poetry.utils.password_manager import PasswordManager
password_manager = PasswordManager(config)
if self.option("unset"):
if m.group(1) == "http-basic":
password_manager.delete_http_password(m.group(2))
elif m.group(1) == "pypi-token":
password_manager.delete_pypi_token(m.group(2))
return 0
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)
View on GitHub (pinned to 92b74dcfe3)
Solutions
- Provide exactly 1 value (username, then you'll be prompted for password) or 2 values (username password): `poetry config http-basic.pypi myuser mypass`.
- If you want the interactive prompt, pass just the username: `poetry config http-basic.pypi myuser`.
Example fix
# before (error) poetry config http-basic.pypi myuser mypass extra # after poetry config http-basic.pypi myuser mypass
Defensive patterns
Strategy: validation
Validate before calling
def validate_http_basic(values: list[str]) -> None:
if len(values) not in (1, 2):
raise ValueError(
f"Expected 1 (username) or 2 (username, password) arguments, got {len(values)}"
) Type guard
def is_valid_http_basic(values: list[str]) -> bool:
return len(values) in (1, 2) Prevention
- Pass 1 value (username) to be prompted for password, or 2 values (username password).
- Avoid extra arguments beyond username and password.
- Use 'poetry config http-basic.REPO USERNAME' for interactive password entry.
When it happens
Trigger: Running `poetry config http-basic.pypi` (zero values, which hits this path because the prohibited-settings check at line 167 only fires when no value is given AND key starts with 'http-basic' — but the value argument is multiple=True so empty list has falsy len). Or running with 3+ values like `poetry config http-basic.pypi user pass extra`.
Common situations: User omits both username and password expecting an interactive prompt that doesn't trigger (the 1-value prompt path requires exactly 1 arg), or passes extra stray arguments.
Related errors
- Expected only one argument (token), got {len(values)}
- You must pass the url. Example: poetry config repositories.f
- Expected a value for {setting_key} setting.
- You cannot remove the [repositories] section
- You can only specify one package when using the --extras opt
AI-assisted analysis of python-poetry/poetry@92b74dcfe3 (2026-08-04).
Data as JSON: /data/errors/2f0bf87ff36a1576.json.
Report an issue: GitHub.