a bug with keyring import order?

42 views
Skip to first unread message

Matthieu Imbert

unread,
Aug 31, 2013, 4:11:56 AM8/31/13
to python-...@googlegroups.com
Hi,

Using python-keyring v1.6.1, with gnome and python 2.7 (I use a debian testing system), I get a rather odd behavior of python keyring, which can be shown with the following sample code:

import keyring
p = keyring.get_password("foo", "bar")
print "OK" if p else "KO"

assuming password for user "bar" of service "foo" exists in gnome keyring, the code works fine and prints "OK"

now if I add some imports before importing keyring, such as:

from json import *
from pprint import *

import keyring
p = keyring.get_password("foo", "bar")
print "OK" if p else "KO"

then, python keyring is not able to retrieve the password and I get a KO.
This behavior depends on which imports are made before keyring, sometimes OK, sometimes KO, but for some given imports such as the one aboves, the behavior seems to be consistent (I mean: I always get KO, not randomly)

cheers,

Matthieu

Jason R. Coombs

unread,
Aug 31, 2013, 10:44:53 AM8/31/13
to python-...@googlegroups.com
Hi Matthieu. Thanks for using Python Keyring and for the bug report.

There are known issues with keyring and preferred keyring detection. Probably what's happening here is the imports are affecting the order in which certain imports occur and in what order the classes appear for resolution. This non-deterministic behavior is obviously undesirable and has been resolved in Keyring 2.0. There was still some non-deterministic behavior encountered in 2.0 (when launched under demand import) which has subsequently been corrected in 2.0.3.

If you're stuck with keyring 1.x, I suggest you either use a keyring config file to specify the backend (if you don't have control over keyring initialization) or explicitly load a backend before using keyring, something like:

keyring.set_keyring(keyring.backends.OS_X.Keyring())

Hope that helps, and please feel free to follow up if you have additional questions.

Regards,
Jason

Matthieu Imbert

unread,
Sep 2, 2013, 4:01:38 AM9/2/13
to python-...@googlegroups.com
Thanks, Jason

Following your advice, I solved my issue by creating ~/.local/share/python_keyring/keyringrc.cfg containing:
[backend]
default-keyring=keyring.backends.Gnome.Keyring
Reply all
Reply to author
Forward
0 new messages