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

No recommended backend was available. #568

Open
jaraco opened this issue Apr 4, 2022 · 10 comments
Open

No recommended backend was available. #568

jaraco opened this issue Apr 4, 2022 · 10 comments
Labels

Comments

@jaraco
Copy link
Owner

jaraco commented Apr 4, 2022

+1
happens for me on my mac with M1. It seems he doesn't find the backend, but it exists.
The fix was to use pip install keyrings.alt so it installs an alternative backend, but I can't see the entered password on the keychain, it seems independent from the system keychain, which is annoying.

Originally posted by @PyMarc2 in #566 (comment)

@jaraco
Copy link
Owner Author

jaraco commented Apr 4, 2022

@PyMarc2 Although you encountered the same error message, that message can happen any time you don't have a viable backend. The issue reported in the other issue is due to issues on Windows Subsystem for Linux (WSL), so probably not relevant to your ARM-based mac, so I've opened up a separate issue.

@jaraco jaraco added the macOS label Apr 4, 2022
@jaraco
Copy link
Owner Author

jaraco commented Apr 4, 2022

I also have an M1 mac, but everything works correctly. What version of Python are you running? Proper support for ARM-based macs wasn't added until Python 3.8.10 or so, and the underlying backend will be broken and thus unavailable. See #525 and #529.

The fix was to use pip install keyrings.alt so it installs an alternative backend, but I can't see the entered password on the keychain, it seems independent from the system keychain, which is annoying.

Although installing keyrings.alt will stop the error message from happening, it's not doing what you want. Since the default keychain-backed backend isn't available, installing keyrings.alt enables another backend, a plain text file system backend that will store your passwords in plain text on your hard drive. That's why you don't see the passwords in the keychain and why it's probably not what you want.

@PyMarc2
Copy link

PyMarc2 commented Apr 5, 2022

I'm using python 3.9.5 with
When I try to add a password with the command keyring set "system" "username"
it returns the following error come:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/bin/keyring", line 8, in <module>
    sys.exit(main())
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/keyring/cli.py", line 132, in main
    return cli.run(argv)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/keyring/cli.py", line 68, in run
    return method()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/keyring/cli.py", line 85, in do_set
    set_password(self.service, self.username, password)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/keyring/core.py", line 60, in set_password
    get_keyring().set_password(service_name, username, password)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/keyring/backends/fail.py", line 25, in get_password
    raise NoKeyringError(msg)
keyring.errors.NoKeyringError: No recommended backend was available. Install a recommended 3rd party backend package; or, install the keyrings.alt package if you want to use the non-recommended backends. See https://pypi.org/project/keyring for details.

@jaraco
Copy link
Owner Author

jaraco commented Jul 14, 2022

Unfortunately, the error message "No recommended backend was available" only tells us that when it tried to detect the macOS backend, it failed to do so.

Can you troubleshoot in your environment by inputting these into a Python interpreter?

>>> from keyring.backends.macOS import Keyring
>>> Keyring.priority
5
>>> from keyring.backends.macOS import api

I suspect you'll get different output than I did on my M1 mac.

@hsperr
Copy link

hsperr commented Nov 10, 2022

I encountered a similar issue when installing keyring on the system of a friend. (On my M1 Pro it works, on his M1 macbook, I am not sure right now which one it is it doesn't)

I got the same error as PyMarc2 mentioned. After digging around I found in a related stackoverflow post that we should explicitly set the backend. After adding

keyring.core.set_keyring(keyring.core.load_keyring('keyring.backends.OS_X.Keyring'))

to the code I receive this error:

  File "/opt/miniconda3/lib/python3.9/site-packages/keyring/backends/macOS/init.py", line 32, in priority
    raise RuntimeError("Security API unavailable")
RuntimeError: Security API unavailable

Unfortunately I think the relevant error is suppressed here:

I will try to print the error on my friends install and see what I can get

@jaraco
Copy link
Owner Author

jaraco commented Nov 11, 2022

Unfortunately I think the relevant error is suppressed here:

The error is intentionally suppressed because that import is known to fail on other platforms. On macOS, however, that import should succeed.

You'll want to do as recommended above and run the troubleshooting steps to help elicit the underlying failure.

>>> from keyring.backends.macOS import Keyring
>>> Keyring.priority
5
>>> from keyring.backends.macOS import api

@hsperr
Copy link

hsperr commented Nov 11, 2022

As I mentioned the whole thing is remote, and he is currently traveling but I had him execute this line:

from keyring.backends.macOS import api

Trace:

Traceback (most recent call last):
  File "/Users/------/Documents/nannuoshan/Codes/nannoushan/src/keyring_inserter.py", line 4, in <module>
    from keyring.backends.macOS import api
  File "/opt/miniconda3/lib/python3.9/site-packages/keyring/backends/macOS/api.py", line 45, in <module>
    SecItemAdd = _sec.SecItemAdd
  File "/opt/miniconda3/lib/python3.9/ctypes/init.py", line 395, in getattr
    func = self.getitem(name)
  File "/opt/miniconda3/lib/python3.9/ctypes/init.py", line 400, in getitem
    func = self._FuncPtr((name_or_ordinal, self))
AttributeError: dlsym(RTLD_DEFAULT, SecItemAdd): symbol not found

@jaraco
Copy link
Owner Author

jaraco commented Nov 11, 2022

That's interesting. That error indicates that _sec.SecItemAdd doesn't exist... like the framework libraries are missing core interfaces supplied by Apple. The error appears after at least some functions are loaded from 'Foundation', but it's the first attempt to address something from _sec (aka ctypes.CDLL(find_library('Security'))). I suspect that library is either defective or masked by some other library.

Next thing I would inspect is to see if the security command works and if the Keychain app works. I'm hopeful one of those is also broken, which will give some indication as to what is wrong with the user's machine, independent of keyring. If both of those are working, then we'll need to do some more experimentation with the user's environment.

@hsperr
Copy link

hsperr commented Dec 7, 2022

So it took a while since he is travelling a lot but to me it seems that both the security command and the keychain app look unsuspicious.

> security list-keychains
    "/Users/<username>/Library/Keychains/login.keychain-db"
    "/Library/Keychains/System.keychain"

I have the same output on my system. And opening the keychain app doesn't seem a problem and passwords seem to be stored like normal. I am not quite sure what exactly to test.

Running keyring I can find the difference that his system doesn't list the OSX keyring.
Are there any libraries that get installed with the dev tools or something that we could try reinstalling?

keyring --list-backends

his system:

keyring.backends.fail.Keyring (priority: 0)
keyring.backends.chainer.ChainerBackend (priority: -1)

my system:

keyring.backends.macOS.Keyring (priority: 5)
keyring.backends.fail.Keyring (priority: 0)
keyring.backends.chainer.ChainerBackend (priority: -1)

@jaraco
Copy link
Owner Author

jaraco commented Dec 7, 2022

So it seems the issue is isolated to this Python environment (not an issue in the system as security and Keychain App are working).

I'm now wondering if there's something odd about how the miniconda3 environment is created. Can you confirm that your friend is also using an M1 mac? Can they try installing Python 3.9.x from the Python.org installer and use it to install keyring and see if the issue occurs there also?

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

No branches or pull requests

3 participants