![](/img/trans.png)
[英]reading credentials from jenkins credential manager and integrating with python script
[英]keyring.get_password() throws NameError when reading credential from Windows Credential Manager
我正在嘗試在 Windows 系統上實現密鑰環來管理 pyodbc 和 sqlalchemy 中連接字符串的數據庫密碼。 我已嘗試確保已安裝拋出的 NameError(s) 中的相關軟件包。
這是我運行的代碼:`
from keyring.backends import Windows
import keyring
keyring.set_keyring(Windows.WinVaultKeyring())
keyring.get_password("Service", "Username")
以下是拋出的錯誤:
Traceback (most recent call last):
File ".\Python310\lib\site-packages\keyring\backends\Windows.py", line 109, in _get_password
res = win32cred.CredRead(
NameError: name 'win32cred' is not defined
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File ".\Python310\lib\site-packages\keyring\core.py", line 55, in get_password
return get_keyring().get_password(service_name, username)
File ".\Python310\lib\site-packages\keyring\backends\Windows.py", line 99, in get_password
res = self._get_password(service)
File ".\Python310lib\site-packages\keyring\backends\Windows.py", line 112, in _get_password
except pywintypes.error as e:
NameError: name 'pywintypes' is not defined
列出了已安裝的軟件包:
包裹 | 版本 |
---|---|
小行星 | 2.9.3 |
回撥 | 0.2.0 |
證書 | 2021.10.8 |
中菲 | 1.15.0 |
字符集規范化器 | 2.0.12 |
雲泡菜 | 2.1.0 |
顏色 | 0.4.4 |
類型 | 1.1.11 |
密碼學 | 37.0.2 |
黎明 | 2022.6.1 |
執行 | 0.8.3 |
文件規范 | 2022.5.0 |
綠地 | 1.1.2 |
伊娜 | 3.3 |
ipython-genutils | 0.2.0 |
異類 | 5.10.1 |
鑰匙圈 | 23.6.0 |
惰性對象代理 | 1.7.1 |
掛墜盒 | 1.0.0 |
麥卡布 | 0.6.1 |
失諧 | 0.8.4 |
鼠標信息 | 0.1.3 |
麻木的 | 1.22.3 |
opencv-python | 4.5.5.64 |
打包 | 21.3 |
熊貓 | 1.4.1 |
分開 | 1.2.0 |
泡菜共享 | 0.7.5 |
枕頭 | 9.1.1 |
點子 | 22.1.2 |
平台目錄 | 2.5.1 |
純評估 | 0.2.2 |
PyAutoGUI | 0.9.53 |
pycparser | 2.21 |
PyGetWindow | 0.0.9 |
皮林特 | 2.12.2 |
PyMsgBox | 1.0.9 |
pyodbc | 4.0.32 |
解析 | 3.0.7 |
彈夾 | 1.8.2 |
PyQt6 | 6.3.1 |
PyQt6-Qt6 | 6.3.1 |
PyQt6-sip | 13.4.0 |
PyRect | 0.2.0 |
PyScreez | 0.1.28 |
pytesseract | 0.3.9 |
蟒蛇比迪 | 0.4.2 |
python-dateutil | 2.8.2 |
pytweening | 1.0.4 |
皮茨 | 2022.1 |
PyWavelets | 1.3.0 |
pywin32 | 303 |
pywin32-ctypes | 0.2.0 |
pywinauto | 0.6.8 |
PyYAML | 6 |
要求 | 2.27.1 |
scipy | 1.8.0 |
Send2Trash | 1.8.0 |
安裝工具 | 58.1.0 |
六 | 1.16.0 |
SQL煉金術 | 1.4.39 |
須藤 | 1.0.0 |
tiff 文件 | 2022.3.16 |
通俗易懂 | 0.10.2 |
工具 | 0.11.2 |
火炬 | 1.11.0 |
火炬音響 | 0.11.0 |
火炬視覺 | 0.12.0 |
特質 | 5.1.1 |
打字擴展 | 4.1.1 |
urllib3 | 1.26.9 |
寬度 | 0.2.5 |
網絡編碼 | 0.5.1 |
包裹 | 1.13.3 |
這是我的設備上額外安裝 python 的問題。
我通過在我的計算機上刪除一組額外的 python 安裝解決了這個問題。
import keyring
keyring.set_keyring(Windows.WinVaultKeyring())
keyring.get_password("Service", "Username")
keyring.set_password("TestService","TestUser", "TestPassword")
keyring.get_password("TestService", "TestUser")
印刷:
'TestPassword'
編輯,這也解決了設置默認密鑰環的需要。 我可以省略: keyring.set_keyring(Windows.WinVaultKeyring())
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.