pypa/pip · error · PipError

Got unexpected number of arguments, expected {n}. (example:

Error message

Got unexpected number of arguments, expected {n}. (example: "{get_prog()} config {example}")

What it means

Raised by ConfigurationCommand._get_n_args when the number of positional arguments to a config subcommand does not match the expected count n. Each subcommand declares its arity (list/debug=0, get/unset=1, set=2); any deviation produces this PipError with an example invocation.

Source

Thrown at src/pip/_internal/commands/configuration.py:263

            )

        try:
            subprocess.check_call(f'{editor} "{fname}"', shell=True)
        except FileNotFoundError as e:
            if not e.filename:
                e.filename = editor
            raise
        except subprocess.CalledProcessError as e:
            raise PipError(f"Editor Subprocess exited with exit code {e.returncode}")

    def _get_n_args(self, args: list[str], example: str, n: int) -> Any:
        """Helper to make sure the command got the right number of arguments"""
        if len(args) != n:
            msg = (
                f"Got unexpected number of arguments, expected {n}. "
                f'(example: "{get_prog()} config {example}")'
            )
            raise PipError(msg)

        if n == 1:
            return args[0]
        else:
            return args

    def _save_configuration(self) -> None:
        # We successfully ran a modifying command. Need to save the
        # configuration.
        try:
            self.configuration.save()
        except Exception:
            logger.exception(
                "Unable to save configuration. Please report this as a bug."
            )
            raise PipError("Internal Error.")

    def _determine_editor(self, options: Values) -> str:

View on GitHub (pinned to d7d0d0a394)

Solutions

  1. Match the arity shown in the error's example: set takes 'command.option value', get/unset take 'command.option', list/debug take nothing.
  2. Quote values containing spaces: pip config set global.index-url 'https://example.org/simple'.
  3. Run 'pip config -h' to confirm each subcommand's signature.

Example fix

// before
pip config set global.index-url
// after
pip config set global.index-url https://pypi.org/simple
Defensive patterns

Strategy: validation

Validate before calling

expected = {"list": 0, "debug": 0, "get": 1, "unset": 1, "set": 2}
if action not in expected:
    raise SystemExit(f"unknown config action {action!r}")
if len(args) != expected[action]:
    raise SystemExit(f"{action} expects {expected[action]} arg(s), got {len(args)}")

Prevention

When it happens

Trigger: E.g. 'pip config set global.index-url' (missing value, expected 2), 'pip config get a b' (expected 1), 'pip config list extra' (expected 0). The helper is called by every config subcommand handler.

Common situations: Forgetting the value for 'set'; passing multiple keys to 'get'; extra tokens after 'list'/'debug'; quoting mistakes that split one value into two.

Related errors


AI-assisted analysis of pypa/pip@d7d0d0a394 (2026-08-04). Data as JSON: /data/errors/48a62ac5244c07c7.json. Report an issue: GitHub.