# Buggy code
def _login(self, username=None, store_password=False, reenter_password=False):
    """
    Login to the ESO User Portal.

    Parameters
    ----------
    username : str, optional
        Username to the ESO Public Portal. If not given, it should be
        specified in the config file.
    store_password : bool, optional
        Stores the password securely in your keyring. Default is False.
    reenter_password : bool, optional
        Asks for the password even if it is already stored in the
        keyring. This is the way to overwrite an already stored passwork
        on the keyring. Default is False.
    """
    if username is None:
        if self.USERNAME == "":
            raise LoginError(
                "If you do not pass a username to login(), "
                "you should configure a default one!"
            )
        else:
            username = self.USERNAME

    # 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

    if password_from_keyring is None:
        if system_tools.in_ipynb():
            log.warning(
                "You may be using an ipython notebook:"
                " the password form will appear in your terminal."
            )
        password = getpass.getpass("{0}, enter your ESO password:\n".format(username))
    else:
        password = password_from_keyring
    # Authenticate
    log.info("Authenticating {0} on www.eso.org...".format(username))

    # Do not cache pieces of the login process
    login_response = self._request("GET", "https://www.eso.org/sso/login", cache=False)
    root = BeautifulSoup(login_response.content, "html5lib")
    login_input = root.find(name="input", attrs={"name": "execution"})
    if login_input is None:
        raise ValueError("ESO login page did not have the correct attributes.")
    execution = login_input.get("value")

    login_result_response = self._request(
        "POST",
        "https://www.eso.org/sso/login",
        data={
            "username": username,
            "password": password,
            "execution": execution,
            "_eventId": "submit",
            "geolocation": "",
        },
    )
    login_result_response.raise_for_status()
    root = BeautifulSoup(login_result_response.content, "html5lib")
    authenticated = root.find("h4").text == "Login successful"

    if authenticated:
        log.info("Authentication successful!")
    else:
        log.exception("Authentication failed!")

    # When authenticated, save password in keyring if needed
    if authenticated and password_from_keyring is None and store_password:
        keyring.set_password("astroquery:www.eso.org", username, password)
    return authenticated


# Traceback (DBusErrorResponse)
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..

# Fixed code
def _login(self, username=None, store_password=False, reenter_password=False):
    """
    Login to the ESO User Portal.

    Parameters
    ----------
    username : str, optional
        Username to the ESO Public Portal. If not given, it should be
        specified in the config file.
    store_password : bool, optional
        Stores the password securely in your keyring. Default is False.
    reenter_password : bool, optional
        Asks for the password even if it is already stored in the
        keyring. This is the way to overwrite an already stored passwork
        on the keyring. Default is False.
    """
    if username is None:
        if self.USERNAME == "":
            raise LoginError(
                "If you do not pass a username to login(), "
                "you should configure a default one!"
            )
        else:
            username = self.USERNAME

    # Get password from keyring or prompt
    password_from_keyring = None
    if reenter_password is False:
        try:
            password_from_keyring = keyring.get_password(
                "astroquery:www.eso.org", username
            )
        except keyring.errors.KeyringError as exc:
            log.warning(
                "Failed to get a valid keyring for password storage: {}".format(exc)
            )

    if password_from_keyring is None:
        if system_tools.in_ipynb():
            log.warning(
                "You may be using an ipython notebook:"
                " the password form will appear in your terminal."
            )
        password = getpass.getpass("{0}, enter your ESO password:\n".format(username))
    else:
        password = password_from_keyring
    # Authenticate
    log.info("Authenticating {0} on www.eso.org...".format(username))

    # Do not cache pieces of the login process
    login_response = self._request("GET", "https://www.eso.org/sso/login", cache=False)
    root = BeautifulSoup(login_response.content, "html5lib")
    login_input = root.find(name="input", attrs={"name": "execution"})
    if login_input is None:
        raise ValueError("ESO login page did not have the correct attributes.")
    execution = login_input.get("value")

    login_result_response = self._request(
        "POST",
        "https://www.eso.org/sso/login",
        data={
            "username": username,
            "password": password,
            "execution": execution,
            "_eventId": "submit",
            "geolocation": "",
        },
    )
    login_result_response.raise_for_status()
    root = BeautifulSoup(login_result_response.content, "html5lib")
    authenticated = root.find("h4").text == "Login successful"

    if authenticated:
        log.info("Authentication successful!")
    else:
        log.exception("Authentication failed!")

    # When authenticated, save password in keyring if needed
    if authenticated and password_from_keyring is None and store_password:
        keyring.set_password("astroquery:www.eso.org", username, password)
    return authenticated