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

3

11

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.

Misdate answered 20/6, 2017 at 3:39 Comment(1)
I have the same problem. Windows 7. Python 3.6. Installed from conda, IIRC. Did you ever solve it?Nosy
M
17

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.

Misdate answered 11/12, 2017 at 23:3 Comment(0)
N
9

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.

Nosy answered 28/11, 2017 at 0:17 Comment(2)
Thanks so much for your response! I didn't think I would ever get this answered. I installed pywin32 and that took care of the exception errors as you described. However I think i'm still unclear on the arguments to use in keyring.get_password. Do you have a quick example you can describe of the credentials you created in Windows Credential Manager and how you extracted the password using keyring? I've tried the following: keyring.get_password("Windows, "test_user") keyring.get_password("Generic", "test_user") My log output for both results shows "None"Misdate
@BrianJ, you're absolutely welcome. Mark as answered?Nosy
D
0

i don't know if you can do that but instead you can ask the user to give it's credentials using this following commands

import admin
if not admin.isUserAdmin():
    admin.runAsAdmin()
Dielectric answered 20/6, 2017 at 6:1 Comment(1)
Thanks for your response. I actually need generic credentials setup in Windows Credential Manager to be passed to the script without any user input to be used in a web scraping application. It seems like keyring would provide this functionality but I can't seem to get it to work with a Windows backend.Misdate

© 2022 - 2024 — McMap. All rights reserved.