Python/keyrings: Difference between revisions
< Python
No edit summary |
|||
| Line 14: | Line 14: | ||
python3 -m pip keyrings.cryptfile | python3 -m pip keyrings.cryptfile | ||
~/.config/python_keyring | ~/.config/python_keyring | ||
Clear cryptfile config and cache: | |||
rm -f ~/.local/share/python_keyring/cryptfile_pass.cfg | |||
rm -rf ~/.local/share/python_keyring | |||
rm -rf ~/.config/python_keyring | |||
--- | --- | ||
| Line 61: | Line 67: | ||
kr.get_password("service", "user") | kr.get_password("service", "user") | ||
</pre> | </pre> | ||
--- | |||
Error: | |||
<pre> | |||
keyring.errors.InitError: Failed to create the collection: Prompt dismissed.. | |||
</pre> | |||
Cause: | |||
: This error occurs because the keyring library is trying to open a secure system dialog to unlock or create a credentials collection, but your environment cannot display it. This is a common issue when running tools like poetry, az cli, or flyte over SSH, inside a headless Linux environment, or within a Docker container where a graphical desktop interface is missing. | |||
Fix: | |||
export PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring | |||
# or | |||
dbus-run-session -- sh | |||
echo -n "your_login_password" | gnome-keyring-daemon --unlock | |||
== keywords == | == keywords == | ||
Revision as of 18:16, 17 September 2026
keyrings
Another keyring db for other usage
sudo apt install python3-keyring python3-keyrings.alt # which also installs: python3-pycryptodome python3-secretstorage # or
python3 -m pip install keyring keyrings.alt
cryptfile
https://pypi.org/project/keyrings.cryptfile/
python3 -m pip keyrings.cryptfile ~/.config/python_keyring
Clear cryptfile config and cache:
rm -f ~/.local/share/python_keyring/cryptfile_pass.cfg rm -rf ~/.local/share/python_keyring rm -rf ~/.config/python_keyring
---
clone cryptfile install
$ git clone https://github.com/frispete/keyrings.cryptfile $ cd keyrings.cryptfile $ pyvenv env $ . env/bin/activate (env) $ pip install -e .
example cryptfile session
(env) $ python3
Python 3.4.5 (default, Jul 03 2016, 12:57:15) [GCC] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from keyrings.cryptfile.cryptfile import CryptFileKeyring
>>> kr = CryptFileKeyring()
>>> kr.set_password("service", "user", "secret")
Please set a password for your new keyring: ******
Please confirm the password: ******
>>> ^d
(env) $ python3
Python 3.4.5 (default, Jul 03 2016, 12:57:15) [GCC] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from keyrings.cryptfile.cryptfile import CryptFileKeyring
>>> kr = CryptFileKeyring()
>>> kr.get_password("service", "user")
Please enter password for encrypted keyring: ******
'secret'
>>> ^d
from getpass import getpass
from os import getenv
from keyrings.cryptfile.cryptfile import CryptFileKeyring
kr = CryptFileKeyring()
kr.keyring_key = getenv("KEYRING_CRYPTFILE_PASSWORD") or getpass()
kr.get_password("service", "user")
---
Error:
keyring.errors.InitError: Failed to create the collection: Prompt dismissed..
Cause:
- This error occurs because the keyring library is trying to open a secure system dialog to unlock or create a credentials collection, but your environment cannot display it. This is a common issue when running tools like poetry, az cli, or flyte over SSH, inside a headless Linux environment, or within a Docker container where a graphical desktop interface is missing.
Fix:
export PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring
# or
dbus-run-session -- sh echo -n "your_login_password" | gnome-keyring-daemon --unlock