{"id":"f565396fb812a8d8","repo":"python-poetry/poetry","slug":"access-to-keyring-was-requested-but-it-is-not-ava","errorCode":null,"errorMessage":"Access to keyring was requested, but it is not available","messagePattern":"Access to keyring was requested, but it is not available","errorType":"exception","errorClass":"PoetryKeyringError","httpStatus":null,"severity":"error","filePath":"src/poetry/utils/password_manager.py","lineNumber":202,"sourceCode":"                \"Accessing keyring failed during availability check\", exc_info=True\n            )\n            return False\n\n        return True\n\n\nclass PasswordManager:\n    def __init__(self, config: Config) -> None:\n        self._config = config\n\n    @atomic_cached_property\n    def use_keyring(self) -> bool:\n        return self._config.get(\"keyring.enabled\") and PoetryKeyring.is_available()\n\n    @atomic_cached_property\n    def keyring(self) -> PoetryKeyring:\n        if not self.use_keyring:\n            raise PoetryKeyringError(\n                \"Access to keyring was requested, but it is not available\"\n            )\n\n        return PoetryKeyring(\"poetry-repository\")\n\n    @staticmethod\n    def warn_plaintext_credentials_stored() -> None:\n        logger.warning(\"Using a plaintext file to store credentials\")\n\n    def set_pypi_token(self, repo_name: str, token: str) -> None:\n        if not self.use_keyring:\n            self.warn_plaintext_credentials_stored()\n            self._config.auth_config_source.add_property(\n                [\"pypi-token\", repo_name], token\n            )\n        else:\n            self.keyring.set_password(repo_name, \"__token__\", token)\n","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/python-poetry/poetry/blob/92b74dcfe348d0e01e14d40d6c1fa47a4ee04a54/src/poetry/utils/password_manager.py#L184-L220","documentation":"The PasswordManager.keyring cached property raises PoetryKeyringError when use_keyring is false, i.e. when config keyring.enabled is false OR PoetryKeyring.is_available() returned false (no importable keyring, only an unsuitable backend such as chainer/fail/null/plaintext, or the availability probe failed). It guards callers from touching the keyring object when it cannot be used.","triggerScenarios":"Accessing PasswordManager.keyring (directly or via set_pypi_token/get_pypi_token paths that require it) while keyring is disabled in config or no suitable backend is available on the host.","commonSituations":"keyring.enabled set to false but code path still requests the keyring; headless box where is_available() is false (only plaintext/null backend); user disabled keyring to avoid plaintext storage.","solutions":["Guard access with `manager.use_keyring` (or PoetryKeyring.is_available()) before touching `manager.keyring`.","Enable the keyring (`poetry config keyring.enabled true`) and install/configure a usable backend (Secret Service, macOS Keychain, etc.).","Run the preflight check (PoetryKeyring.preflight_check) to see why availability failed (debug logs explain the rejected backend).","If keyring is intentionally disabled, route credential storage through config/env instead."],"exampleFix":"# before\nkr = manager.keyring  # raises when keyring disabled/unavailable\n# after\nif manager.use_keyring:\n    kr = manager.keyring\n    kr.set_password(name, user, pw)\nelse:\n    manager.warn_plaintext_credentials_stored()\n    manager._config.auth_config_source.add_property([\"pypi-token\", name], pw)","handlingStrategy":"validation","validationCode":"from poetry.utils.password_manager import PasswordManager, PoetryKeyring\n\n# check both config flag and actual availability before touching .keyring\nif not (manager._config.get('keyring.enabled') and PoetryKeyring.is_available()):\n    raise RuntimeError('keyring not available; use config/env')","typeGuard":null,"tryCatchPattern":"from poetry.utils.password_manager import PoetryKeyringError\ntry:\n    kr = manager.keyring\nexcept PoetryKeyringError:\n    # fall back to non-keyring credential storage\n    kr = None","preventionTips":["Guard every access to manager.keyring with manager.use_keyring.","Run PoetryKeyring.preflight_check to learn why availability failed.","Don't enable keyring.enabled unless a usable backend exists."],"tags":["keyring","configuration","availability","authentication"],"analyzedSha":"92b74dcfe348d0e01e14d40d6c1fa47a4ee04a54","analyzedAt":"2026-08-04T20:33:34.072Z","schemaVersion":2}