python-poetry/poetry · error · ValueError

Expected a value for {setting_key} setting.

Error message

Expected a value for {setting_key} setting.

What it means

Raises ValueError in ConfigCommand.handle() when the user reads (without providing a value) a setting whose top-level key is in LIST_PROHIBITED_SETTINGS ({'http-basic', 'pypi-token'}). These are secret-bearing settings that Poetry never displays, so reading them without a value to set is treated as an error to prevent accidental secret exposure. The check at line 167-168 fires when no value is provided and the key starts with a prohibited segment.

Source

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

        if self.option("list"):
            self._list_configuration(config.all(), config.raw())

            return 0

        setting_key = self.argument("key")
        if not setting_key:
            return 0

        if self.argument("value") and self.option("unset"):
            raise RuntimeError("You can not combine a setting value with --unset")

        repo_regex = r"^repos?(?:itories)?(?:\.(.+?)(?:\.(url))?)?$"

        # show the value if no value is provided
        if not self.argument("value") and not self.option("unset"):
            if setting_key.split(".")[0] in self.LIST_PROHIBITED_SETTINGS:
                raise ValueError(f"Expected a value for {setting_key} setting.")

            value: str | dict[str, Any] | list[str]

            if m := re.match(
                r"installer\.build-config-settings(\.([^.]+))?", self.argument("key")
            ):
                if not m.group(1):
                    if value := config.get("installer.build-config-settings"):
                        self._list_configuration(value, value)
                    else:
                        self.line("No packages configured with build config settings.")
                else:
                    package_name = canonicalize_name(m.group(2))
                    key = f"installer.build-config-settings.{package_name}"

                    if value := config.get(key):
                        self.line(json.dumps(value))
                    else:

View on GitHub (pinned to 92b74dcfe3)

Solutions

  1. Provide the value when setting: `poetry config http-basic.pypi username password` or `poetry config pypi-token.pypi <token>`.
  2. Use --unset to remove the credential: `poetry config http-basic.pypi --unset`.
  3. Poetry intentionally does not allow reading back secrets; use your keyring or OS credential store to inspect stored values.

Example fix

# before (error)
poetry config pypi-token.pypi
# after (to set)
poetry config pypi-token.pypi pypi-xxxxxxxx
Defensive patterns

Strategy: validation

Validate before calling

PROHIBITED = {"http-basic", "pypi-token"}

def validate_config_read(key: str, has_value: bool) -> None:
    if not has_value and key.split(".")[0] in PROHIBITED:
        raise ValueError(
            f"Reading '{key}' is not allowed; provide a value to set or use --unset"
        )

Type guard

PROHIBITED = {"http-basic", "pypi-token"}

def is_safe_config_read(key: str, has_value: bool) -> bool:
    return has_value or key.split(".")[0] not in PROHIBITED

Prevention

When it happens

Trigger: Running `poetry config http-basic.pypi` or `poetry config pypi-token.pypi` without passing a value and without --unset. The command interprets this as a read attempt on a secret setting.

Common situations: User tries to inspect a stored credential, or forgets to append the username/password/token value when setting it.

Related errors


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