Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import keyring fails with AttributeError when dbus is partially available #296

Closed
jaraco opened this issue Dec 15, 2017 · 0 comments
Closed

Comments

@jaraco
Copy link
Owner

jaraco commented Dec 15, 2017

I have a Linux environment (Ubuntu Xenial) created with python3-dbus (implicitly) installed but also python3.6 installed from the deadsnakes repo. In this environment, the dbus package is available (in /usr/local/lib/python3/dist-packages) but the underlying _dbus_bindings is not available (because the bindings were compiled for Python 3.5). In that environment, if one attempts to import dbus, one gets:

>>> import dbus
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/dbus/__init__.py", line 82, in <module>
    import dbus.types as types
  File "/usr/lib/python3/dist-packages/dbus/types.py", line 6, in <module>
    from _dbus_bindings import (
ModuleNotFoundError: No module named '_dbus_bindings'

If one attempts to import dbus again, a different error occurs:

>>> import dbus
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/dbus/__init__.py", line 81, in <module>
    import dbus.exceptions as exceptions
AttributeError: module 'dbus' has no attribute 'exceptions'

And because keyring has two modules each of which attempt to import dbus but trapping only ImportErrors, the import will fail.

>>> import keyring
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/keyring/__init__.py", line 3, in <module>
    from .core import (set_keyring, get_keyring, set_password, get_password,
  File "/usr/local/lib/python3.6/dist-packages/keyring/core.py", line 153, in <module>
    init_backend()
  File "/usr/local/lib/python3.6/dist-packages/keyring/core.py", line 66, in init_backend
    keyrings = filter(limit, backend.get_all_keyring())
  File "/usr/local/lib/python3.6/dist-packages/keyring/util/__init__.py", line 21, in wrapper
    func.always_returns = func(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/keyring/backend.py", line 184, in get_all_keyring
    _load_backends()
  File "/usr/local/lib/python3.6/dist-packages/keyring/backend.py", line 142, in _load_backends
    list(map(_load_backend, backends))
  File "/usr/local/lib/python3.6/dist-packages/keyring/backend.py", line 133, in _load_backend
    mod = importlib.import_module('.' + name, package)
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/usr/local/lib/python3.6/dist-packages/keyring/backends/kwallet.py", line 12, in <module>
    import dbus
  File "/usr/lib/python3/dist-packages/dbus/__init__.py", line 81, in <module>
    import dbus.exceptions as exceptions
AttributeError: module 'dbus' has no attribute 'exceptions'

In my opinion, this is an upstream issue in either Ubuntu or dbus, but keyring should probably work around the bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant