5

I have the following python test code:

import keyring
print(keyring.get_keyring())
keyring.set_password("a","b","c")
print(keyring.get_password("a","b"))

If I run this code using a 32 bit python or a 64 bit one I obtain the following output (as expected):

<keyring.backends.Windows.WinVaultKeyring object at 0x00000187B7DD6358>
c

My purpose is to build two standalone executable (32bit and 64bit): in order to achieve that I'm using pyinstaller and the following command (test.py is the name of the file containing the python code shown above)

pyinstaller --onefile test.py

If I run the 64 bit exe I obtain the following output (as expected):

<keyring.backends.Windows.WinVaultKeyring object at 0x00000187B7DD6358>
c

Instead, if I run the 32 bit exe I obtain the following output:

<keyring.backends.fail.Keyring object at 0x05463ED0>
Traceback (most recent call last):
  File "test.py", line 3, in <module>
    keyring.set_password("a","b","c")
  File "site-packages\keyring\core.py", line 47, in set_password
  File "site-packages\keyring\backends\fail.py", line 23, in get_password
RuntimeError: No recommended backend was available. Install the keyrings.alt package if you want to use the non-recommended backends. See README.rst for details.
[2732] Failed to execute script test

Does anyone know what is going on?

Thanks,

Daniele

Daniele Milani
  • 553
  • 2
  • 7
  • 26
  • How do you obtain your 32 bit executable? If you want your final exe to be executable on both 32 and 64 bits, you should install `pyinstaller` with your 32 bits version of python and produce the exe from there. – Jacques Gaudin May 31 '18 at 14:13
  • I'm using a 32 bits python to produce the executable: anyway I just solved the issue using an alternate keyring (see the answer below). – Daniele Milani May 31 '18 at 15:54

2 Answers2

1

Solved using an alternate keyring backend. If I change my code from:

import keyring
print(keyring.get_keyring())
keyring.set_password("a","b","c")
print(keyring.get_password("a","b"))

to:

import keyring
from keyrings.alt import Windows
keyring.set_keyring(Windows.RegistryKeyring())
print(keyring.get_keyring())
keyring.set_password("a","b","c")
print(keyring.get_password("a","b"))

it works.

Daniele Milani
  • 553
  • 2
  • 7
  • 26
1

Setting up the keyrings.alt file from the Keyring Github page does seem to work, and would explain why this was only an issue in Keyring>12, since it was included in the Module before that. I was also able to work around it by installing pip install pywin32 and running the following additions:

import keyring
import win32timezone
from keyring.backends import Windows
keyring.set_keyring(Windows.WinVaultKeyring())
print(keyring.get_keyring())
keyring.set_password("a","b","c")
print(keyring.get_password("a","b"))
dkrookey
  • 11
  • 3