Astroquery: Login not possible when keyring cannot find a valid storage

Created on 13 Jul 2018  路  4Comments  路  Source: astropy/astroquery

When login on a server, I get this exception:

In [1]: from astroquery.eso import Eso
eso                                                                        
In [2]: eso = Eso()                                                                                         

In [3]: eso.login(username='MUSE-XXX')                                        
---------------------------------------------------------------------------
DBusErrorResponse                         Traceback (most recent call last)
~/miniconda3/lib/python3.6/site-packages/secretstorage/util.py in send_and_get_reply(self, msg)                    
     40                 try:                                           
---> 41                         return self._connection.send_and_get_reply(msg)
     42                 except DBusErrorResponse as resp:

~/miniconda3/lib/python3.6/site-packages/jeepney/integrate/blocking.py in send_and_get_reply(self, message)                 
     48                      
---> 49         return future.result()                                  
     50                                            

DBusErrorResponse: [org.freedesktop.DBus.Error.UnknownMethod] ("No such interface 'org.freedesktop.DBus.Properties' on object at path /org/freedesktop/secrets/collection/login",)

The above exception was the direct cause of the following exception:
...

InitError                                 Traceback (most recent call last)
<ipython-input-3-9186902b997a> in <module>()
----> 1 eso.login(username='MUSE-GTO')

~/lib/astroquery/astroquery/query.py in login(self, *args, **kwargs)
    335     def login(self, *args, **kwargs):
    336         with suspend_cache(self):
--> 337             self._authenticated = self._login(*args, **kwargs)
    338         return self._authenticated
    339

~/lib/astroquery/astroquery/eso/core.py in _login(self, username, store_password, reenter_password)
    220         if reenter_password is False:
    221             password_from_keyring = keyring.get_password(
--> 222                 "astroquery:www.eso.org", username)
    223         else:
    224             password_from_keyring = None

~/miniconda3/lib/python3.6/site-packages/keyring/core.py in get_password(service_name, username)
     39     """Get password from the specified service.
     40     """
---> 41     return _keyring_backend.get_password(service_name, username)
     42
     43

~/miniconda3/lib/python3.6/site-packages/keyring/backends/SecretService.py in get_password(self, service, username)
     65         """Get password of the username for the service
     66         """
---> 67         collection = self.get_preferred_collection()
     68         items = collection.search_items(
     69             {"username": username, "service": service})

~/miniconda3/lib/python3.6/site-packages/keyring/backends/SecretService.py in get_preferred_collection(self)
     55                 collection = secretstorage.get_default_collection(bus)
     56         except exceptions.SecretStorageException as e:
---> 57             raise InitError("Failed to create the collection: %s." % e)
     58         if collection.is_locked():
     59             collection.unlock()

InitError: Failed to create the collection: Prompt dismissed..

I don't know why exactly (no dbus, gnome-keyring or whatever) but this should not prevent to login without storing the password. I can workaround this by using reenter_password=False but this is not obvious (login parameters are not documented).
So I guess the simple solution would be to try/except the keyring.get_password call :

        # Get password from keyring or prompt
        if reenter_password is False:
            password_from_keyring = keyring.get_password(
                "astroquery:www.eso.org", username)
        else:
            password_from_keyring = None
bug infrastructure

Most helpful comment

It's unfortunate that keyring is causing us problems, but I agree with the solution of trying to get the password and giving up if there's a keyring-related failure

All 4 comments

@saimn - What is your keyring version? We had issues with v12.0+ on CI, so if you have one of those, could you please try it with an older one, too?

@bsipocz - I have 12.2.1, let's try with another one.

I get the same error with 11.1.0 and 13.2.1.

It's unfortunate that keyring is causing us problems, but I agree with the solution of trying to get the password and giving up if there's a keyring-related failure

Was this page helpful?
0 / 5 - 0 ratings