1
我使用Python 2.7中的Gtk3中的GnomeKeyring,但几乎所有的方法都被弃用[1]。所以我试图用SecretSecret.Collection [2]如何通过秘密存储集合中的标签找到密钥
import gi
gi.require_version('Secret', '1.0')
from gi.repository import Secret
>> ValueError: Namespace Secret not available
我发现包 “中的python-secretstorage”[3],并且可以访问现在钥匙圈:
import secretstorage
bus = secretstorage.dbus_init()
collection = secretstorage.get_default_collection(bus) ## login keyring
但我怎么能找到键我正在通过标签搜索,所以我不必遍历所有项目?
items = collection.get_all_items()
for item in items:
if item.get_label() == "most_wanted_key":
return item
这是我试过的,但它不适用于标签,只有属性(s)。
found_items = collection.search_items({"label": "most_wanted_key"})
- https://lazka.github.io/pgi-docs/GnomeKeyring-1.0/functions.html
- https://lazka.github.io/pgi-docs/Secret-1/classes/Collection.html
- https://secretstorage.readthedocs.io/en/latest/