gnome-keyring with Python
The documentation on gnome-keyring I discovered helped me to access it successfully with Python. I've written a small module that fetches and stores a username and a password for some server.
Some notes:
-
The attributes are freeform, but there a some common attributes for network hosts. These are:
"user","domain","server","object","protocol","authtype", and"port". Actually there is a convenience API for network hosts. -
libgnome-keyring requires that the application is correctly set using
g_set_application_name. Unfortunately the Python modulegnomekeyringdoes not do that for us and pygtk does not provide a function to set the application name. Therefore you need to include the modulegtkto make it work. (Filed as bug 460515.)Update:
g_set_application_namewas added to pygtk in the 2.13 development version. -
Python's
find_network_password_syncfunction does not allowNoneto be passed as arguments. The C API allowsNULLto be passed here. This means that this function is basically unusable in Python, since you never want to provide all values. (Filed as bug 460518.)
could you provide a license for the module
by 0x89
Wednesday, 25 November 2009 23:47
I know it is not big, but as you are the no 1 hit for "python gnome keyring" on google, could you provide a license for your module? If not specified, the module cannot be used in any open source tools.
License
by Sebastian Rittau
Thursday, 26 November 2009 09:53
Consider this module to be in the Public Domain. (I'd probably have a hard time to claim any rights under German Copyright law for something trivial as this in any case ...)
NoMatchError
by David
Monday, 4 January 2010 05:59
has_credentials() was failing for me with a NoMatchError so I added:
except gkey.NoMatchError:
return False
I'm using python 2.6.4 on Ubuntu 9.10.
I'm not sure the DeniedError should ever happen. As far as I can see it should only happen if you've already got the same entry but added by a different application and in that case I don't think you actually want to return false, I think you want to pass the error up the function stack.