How do you Configure Python Keyring to pull credentials from Windows Credential Manager on Windows 7?

13,024

Solution 1

Finally got this working. The information from Shaun pointed me in the right direction with installing pywin32. From there I did trial and error with creating test credentials in Windows Credential Manager and testing the Python keyring function.

I only got it working with Generic Credentials which is fine for my purposes. I set Internet or network address to "test". Username was set to "test_user". Password was set to "test123". (Quotes included here for instruction, don't include when entering them.

print keyring.get_password("test","test_user") 

returned the result "test123"

Hopefully this information helps somebody else. Thanks to Shaun for the direction needed to solve this.

Solution 2

You may have to install the pywin32 package. Doing so solved the problem for me.

Using conda:
conda install -e environment_name_here pywin32

Using pip:
pip install pywin32

On a tangent: For some reason, the code swallows an exception that the windows credential manager class would have otherwise thrown to alert you to this problem. Here's the exception and here's where it's caught and thrown away.

Share:
13,024
Brian J
Author by

Brian J

Updated on June 21, 2022

Comments

  • Brian J
    Brian J almost 2 years

    I've spent a lot of time researching the keyring package trying to get a simple example to work. I'm using python 2.7 on a windows 7-x64 machine. I've installed the package and confirmed that the files are within my Lib/site-packages folder.

    In this code snippet from the installation docs what is supposed to go in "system"?

    import keyring
    keyring.get_password("system", "username")
    

    When I run the code i get the following error:

    RuntimeError: No recommended backend was available. Install the keyrings.alt package if you want to use the non-recommended backends.

    It seems like it's not recognizing Windows as the backend. I feel like I'm missing a simple step. Any help is appreciated including a simple code example of pulling generic credentials from Windows Credential Manager.