pypa/pip · error · ConfigurationError
No such key - {orig_key}
Error message
No such key - {orig_key} What it means
Raised as ConfigurationError in Configuration.get_value() at configuration.py:157 when the normalized key is not found in the merged configuration dictionary. Note _disassemble_key is called first (line 156), so this specific message only appears when the key HAS a dot (a dot-less key raises error [52] instead). The orig_key in the message is the un-normalized key the caller supplied.
Source
Thrown at src/pip/_internal/configuration.py:157
"""Returns key-value pairs like dict.items() representing the loaded
configuration
"""
return self._dictionary.items()
def get_value(self, key: str) -> Any:
"""Get a value from the configuration."""
orig_key = key
key = _normalize_name(key)
try:
clean_config: dict[str, Any] = {}
for file_values in self._dictionary.values():
clean_config.update(file_values)
return clean_config[key]
except KeyError:
# disassembling triggers a more useful error message than simply
# "No such key" in the case that the key isn't in the form command.option
_disassemble_key(key)
raise ConfigurationError(f"No such key - {orig_key}")
def set_value(self, key: str, value: Any) -> None:
"""Modify a value in the configuration."""
key = _normalize_name(key)
self._ensure_have_load_only()
assert self.load_only
fname, parser = self._get_parser_to_modify()
if parser is not None:
section, name = _disassemble_key(key)
# Modify the parser and the configuration
if not parser.has_section(section):
parser.add_section(section)
parser.set(section, name, value)
self._config[self.load_only].setdefault(fname, {})View on GitHub (pinned to d7d0d0a394)
Solutions
- Verify the key exists with 'pip config list' or 'pip config debug'.
- Check spelling — keys are normalized (lowercase, dashes for underscores), so use the canonical form like 'global.index-url'.
- Ensure Configuration.load() has been called before get_value().
- If using get_value programmatically, catch ConfigurationError to handle missing keys gracefully.
Example fix
# before pip config get global.retries # not set -> error # after pip config set global.retries 5 pip config get global.retries
Defensive patterns
Strategy: validation
Validate before calling
from pip._internal.configuration import Configuration
from pip._internal.exceptions import ConfigurationError
def safe_get_value(cfg: Configuration, key: str, default=None):
cfg.load()
try:
return cfg.get_value(key)
except ConfigurationError:
return default
# Usage
val = safe_get_value(cfg, 'global.retries', default=5) Type guard
from pip._internal.configuration import Configuration
def key_exists(cfg: Configuration, key: str) -> bool:
cfg.load()
try:
cfg.get_value(key)
return True
except Exception:
return False Try / catch
from pip._internal.exceptions import ConfigurationError
try:
value = cfg.get_value('global.retries')
except ConfigurationError as e:
if 'No such key' in str(e):
value = None # treat as missing
else:
raise Prevention
- Call Configuration.load() before get_value().
- Check 'pip config list' / 'pip config debug' for valid key names.
- Catch ConfigurationError and provide a sensible default when a missing key is expected.
When it happens
Trigger: Calling Configuration.get_value('global.nonexistent') (or via 'pip config get global.nonexistent') when that key is absent from all loaded config variants. The KeyError at line 153 is caught and re-raised as this ConfigurationError.
Common situations: Querying a config key that was never set; typo in the key name; querying before Configuration.load() was called; expecting a default that pip does not actually store in config.
Related errors
- Key does not contain dot separated section and key. Perhaps
- Got invalid value for load_only - should be one of {}
- Fatal Internal error [id=1]. Please report as a bug.
- An error occurred while writing to the configuration file {f
- Needed a specific file to be modifying.
AI-assisted analysis of pypa/pip@d7d0d0a394 (2026-08-04).
Data as JSON: /data/errors/bb103c0abff14508.json.
Report an issue: GitHub.