May 18, 2010

Bending Gnome Keyring with Python – Part 2

In the last post we started introducing how the Gnome Keyring works. I showed how to create a keyring and its items using Seahorse, now I’m going to show how to do it using Python. In order to interact with Gnome Keyring from Python we need python-gnomekeyring installed. Let’s start bending…

 

Exploring Gnome Keyring

As a first step, I’ll show how to “explore” Gnome Keyring. A good start is ensure that the Gnome keyring Daemon is available using the is_available method. To search through existing keyrings we can use the list_keyring_names_sync method. If you test this from a Python Console you will notice an recurrent warning “g_set_application_name not set”, an example:

>>> importgnomekeyring as gk
>>> gk.list_keyring_names_sync()
**(process:1737): WARNING **: g_set_application_name notset.
['login', 'MyKeyring', 'session']
>>>

This happens because the daemon requests information about which application is trying to access the Gnome Keyring info and as a Python Console we don’t have any application name. To solve this, we can import the gobject library and use the method set_application_name. Below, there is a simple keyring listing example:

 

Read more...

Click Here!