[Python] Password Storage for Python Scripts

Discussão em 'Python' iniciado por Stack, Setembro 10, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to work with some scripts that will require logon credentials to access systems. After some troubleshooting I found that 'keyring' is causing me some issues. I've searched all over and can't seem to find how to fix my issue.

    From what I can tell there is a prompt on systems with a GUI and that makes sense however I'll be using a headless Ubuntu system. Can anyone lead me in the right direction here? I've seen all kinds of search results but nothing seems to make sense to resolve the issue.

    Python 3.12.3 (main, Aug 14 2025, 17:47:21) [GCC 13.3.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import keyring
    >>> keyring.set_password("test_app", "testuser", "testpassword")
    Traceback (most recent call last):
    File "/usr/local/lib/python3.12/dist-packages/secretstorage/util.py", line 48, in send_and_get_reply
    raise DBusErrorResponse(resp_msg)
    jeepney.wrappers.DBusErrorResponse: [org.freedesktop.DBus.Error.UnknownMethod] ('Object does not exist at path “/org/freedesktop/secrets/collection/login”',)

    The above exception was the direct cause of the following exception:

    Traceback (most recent call last):
    File "/usr/local/lib/python3.12/dist-packages/secretstorage/collection.py", line 177, in get_default_collection
    return Collection(connection)
    ^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/local/lib/python3.12/dist-packages/secretstorage/collection.py", line 45, in __init__
    self._collection.get_property('Label')
    File "/usr/local/lib/python3.12/dist-packages/secretstorage/util.py", line 67, in get_property
    (signature, value), = self.send_and_get_reply(msg)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/local/lib/python3.12/dist-packages/secretstorage/util.py", line 52, in send_and_get_reply
    raise ItemNotFoundException('Item does not exist!') from resp
    secretstorage.exceptions.ItemNotFoundException: Item does not exist!

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "/usr/lib/python3/dist-packages/keyring/backends/SecretService.py", line 61, in get_preferred_collection
    collection = secretstorage.get_default_collection(bus)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/local/lib/python3.12/dist-packages/secretstorage/collection.py", line 179, in get_default_collection
    return create_collection(connection, 'Default', 'default', session)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/local/lib/python3.12/dist-packages/secretstorage/collection.py", line 159, in create_collection
    raise PromptDismissedException('Prompt dismissed.')
    secretstorage.exceptions.PromptDismissedException: Prompt dismissed.

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "/usr/lib/python3/dist-packages/keyring/core.py", line 61, in set_password
    get_keyring().set_password(service_name, username, password)
    File "/usr/lib/python3/dist-packages/keyring/backends/chainer.py", line 56, in set_password
    return keyring.set_password(service, username, password)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/lib/python3/dist-packages/keyring/backends/SecretService.py", line 87, in set_password
    collection = self.get_preferred_collection()
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/lib/python3/dist-packages/keyring/backends/SecretService.py", line 63, in get_preferred_collection
    raise InitError("Failed to create the collection: %s." % e)
    keyring.errors.InitError: Failed to create the collection: Prompt dismissed..
    >>>

    Continue reading...

Compartilhe esta Página