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

Importing keyring fails (because of secretstorage requirement) #338

Closed
saimn opened this issue Jul 26, 2018 · 5 comments
Closed

Importing keyring fails (because of secretstorage requirement) #338

saimn opened this issue Jul 26, 2018 · 5 comments

Comments

@saimn
Copy link

saimn commented Jul 26, 2018

I'm having some trouble with keyring on a server, on which I don't want to configure / use Dbus (I could try to setup dbus, but I don't want to explain this to every user of my code).

Currently keyring is imported on a dependency of my project, and it has secretstorage as dependency, which means that I cannot even import keyring:

(base) ❯ python -c "import keyring"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/conseil/miniconda3/lib/python3.6/site-packages/keyring/__init__.py", line 3, in <module>
    from .core import (set_keyring, get_keyring, set_password, get_password,
  File "/home/conseil/miniconda3/lib/python3.6/site-packages/keyring/core.py", line 154, in <module>
    init_backend()
  File "/home/conseil/miniconda3/lib/python3.6/site-packages/keyring/core.py", line 67, in init_backend
    keyrings = filter(limit, backend.get_all_keyring())
  File "/home/conseil/miniconda3/lib/python3.6/site-packages/keyring/util/__init__.py", line 21, in wrapper
    func.always_returns = func(*args, **kwargs)
  File "/home/conseil/miniconda3/lib/python3.6/site-packages/keyring/backend.py", line 179, in get_all_keyring
    exceptions=TypeError))
  File "/home/conseil/miniconda3/lib/python3.6/site-packages/keyring/util/__init__.py", line 31, in suppress_exceptions
    for callable in callables:
  File "/home/conseil/miniconda3/lib/python3.6/site-packages/keyring/backend.py", line 171, in is_class_viable
    keyring_cls.priority
  File "/home/conseil/miniconda3/lib/python3.6/site-packages/keyring/util/properties.py", line 24, in __get__
    return self.fget.__get__(None, owner)()
  File "/home/conseil/miniconda3/lib/python3.6/site-packages/keyring/backends/SecretService.py", line 37, in priority
    bus = secretstorage.dbus_init()
  File "/home/conseil/miniconda3/lib/python3.6/site-packages/secretstorage/__init__.py", line 41, in dbus_init
    return connect_and_authenticate()
  File "/home/conseil/miniconda3/lib/python3.6/site-packages/jeepney/integrate/blocking.py", line 72, in connect_and_authenticate
    sock.connect(bus_addr)
ConnectionRefusedError: [Errno 111] Connection refused

It makes it impossible to list backends, or to view the config path, or even to change the backend! (even if I set keyrings.alt.file.PlaintextKeyring in the config file).

I can uninstall secretstorage, then keyring work and can use keyrings.alt, but then when I run a script using entry_points, pip checks the requirements and fails because secretstorage is missing :(

Traceback (most recent call last):
  File "/home/conseil/miniconda3/bin/musered", line 6, in <module>
    from pkg_resources import load_entry_point
  File "/home/conseil/miniconda3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3095, in <module>
    @_call_aside
  File "/home/conseil/miniconda3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3079, in _call_aside
    f(*args, **kwargs)
  File "/home/conseil/miniconda3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3108, in _initialize_master_working_set
    working_set = WorkingSet._build_master()
  File "/home/conseil/miniconda3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 570, in _build_master
    ws.require(__requires__)
  File "/home/conseil/miniconda3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 888, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/home/conseil/miniconda3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 774, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'secretstorage; sys_platform == "linux" and python_version >= "3.5"' distribution was not found and is required by keyring
@saimn
Copy link
Author

saimn commented Jul 26, 2018

Diving into this a bit more, it could be because recently (version 3.0 released in april) secretstorage switched to jeepney (mitya57/secretstorage@711c931) which is raising a different exception (the ConnectionRefusedError above) than the one catched by keyring (https://github.com/jaraco/keyring/blob/master/keyring/backends/SecretService.py#L39).

So if I pip uninstall jeepney and pip install "secretstorage<3.0", then it works as I would expect, i.e. skipping the Keyring backend...

mitya57 added a commit to mitya57/secretstorage that referenced this issue Jul 26, 2018
@mitya57
Copy link
Collaborator

mitya57 commented Jul 26, 2018

Please try the latest version of SecretStorage from master branch, it should handle such errors properly.

@saimn
Copy link
Author

saimn commented Jul 26, 2018

@mitya57 - Thanks a lot, it should indeed do the job, I will check tomorrow.

@saimn
Copy link
Author

saimn commented Jul 27, 2018

It works, thanks again @mitya57 !

@saimn saimn closed this as completed Jul 27, 2018
@mitya57
Copy link
Collaborator

mitya57 commented Sep 2, 2018

I have just released SecretStorage 3.1.0, which now catches such errors and converts them into its own exceptions (which would be caught by python-keyring).

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

2 participants