Python keyring got error: org.freedesktop.DBus.Error.UnknownMethod: Method "OpenSession" doesn't exist

4.2k views Asked by At

I'm having a problem with python keyring after the installation. here are my steps:

$ python
>>> import keyring
>>> keyring.set_password('something','otherSomething','lotOfMoreSomethings')

and then throws this:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.6/dist-packages/keyring/core.py", line 42, in set_password
   _keyring_backend.set_password(service_name, username, password)
File "/usr/local/lib/python2.6/dist-packages/keyring/backend.py", line 222, in set_password
   _, session = service_iface.OpenSession("plain", "")
File "/usr/lib/pymodules/python2.6/dbus/proxies.py", line 68, in __call__
   return self._proxy_method(*args, **keywords)
File "/usr/lib/pymodules/python2.6/dbus/proxies.py", line 140, in __call__
   **keywords)
File "/usr/lib/pymodules/python2.6/dbus/connection.py", line 630, in call_blocking
   message, timeout)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.UnknownMethod:
   Method "OpenSession" with signature "ss" on interface "org.freedesktop.Secret.Service" 
   doesn't exist

i have installed keyring from here using

easy_install keyring

Do i do anything wrong?? There are any solution??

Edit:

Also i've installed python-keyring and python-keyring-gnome from repos and just import like

>>> import gnome_keyring

and works.

2

There are 2 answers

0
94gC On

I've been having a similar problem but my DBus Exception was on kwalletd (specifically /modules/kwalletd) even though I use Gnome.

My work around was to create a local "keyringrc.cfg" file like so:

[backend]
default-keyring=keyring.backends.Gnome.Keyring

See the Python keyring Package for determining where the Config file path is for your system.

0
Jonathan L On

If using gnomekeyring python package, you can use item_create_sync method to create a new password entry or replace existing password for a given key

#!/usr/bin/env python
import gnomekeyring

gnomekeyring.item_create_sync ("keyring-name", gnomekeyring.ITEM_GENERIC_SECRET, "key-display-name", {}, "password", True)

where item_create_sync method signature is

item_create_sync (string? keyring, ItemType type, string display_name, AttributeList attributes, string secret, bool update_if_exists)