1

遇到密钥环问题:

RuntimeError:无法初始化 SecretService:环境变量 DBUS_SESSION_BUS_ADDRESS 未设置

已安装 SecretService。操作系统是 RHEL

跑步:

python -c "import keyring.backends.SecretService as SS; SS.Keyring.priority"

给出以下错误:

Traceback (most recent call last):
  File "/home/webpage/.pyenv/versions/WEBPAGE/lib/python3.6/site-packages/secretstorage/__init__.py", line 41, in dbus_init
    return connect_and_authenticate()
  File "/home/webpage/.pyenv/versions/WEBPAGE/lib/python3.6/site-packages/jeepney/integrate/blocking.py", line 70, in connect_and_authenticate
    bus_addr = get_bus(bus)
  File "/home/webpage/.pyenv/versions/WEBPAGE/lib/python3.6/site-packages/jeepney/bus.py", line 53, in get_bus
    return find_session_bus()
  File "/home/webpage/.pyenv/versions/WEBPAGE/lib/python3.6/site-packages/jeepney/bus.py", line 42, in find_session_bus
    addr = os.environ['DBUS_SESSION_BUS_ADDRESS']
  File "/home/webpage/.pyenv/versions/3.6.5/lib/python3.6/os.py", line 669, in __getitem__
    raise KeyError(key) from None
KeyError: 'DBUS_SESSION_BUS_ADDRESS'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/webpage/.pyenv/versions/WEBPAGE/lib/python3.6/site-packages/keyring/backends/SecretService.py", line 37, in priority
    bus = secretstorage.dbus_init()
  File "/home/webpage/.pyenv/versions/WEBPAGE/lib/python3.6/site-packages/secretstorage/__init__.py", line 45, in dbus_init
    raise SecretServiceNotAvailableException(reason) from ex
secretstorage.exceptions.SecretServiceNotAvailableException: Environment variable DBUS_SESSION_BUS_ADDRESS is unset

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/webpage/.pyenv/versions/WEBPAGE/lib/python3.6/site-packages/keyring/util/properties.py", line 26, in __get__
    return self.fget.__get__(None, owner)()
  File "/home/webpage/.pyenv/versions/WEBPAGE/lib/python3.6/site-packages/keyring/backends/SecretService.py", line 41, in priority
    "Unable to initialize SecretService: %s" % e)
RuntimeError: Unable to initialize SecretService: Environment variable DBUS_SESSION_BUS_ADDRESS is unset

我怎样才能解决这个问题?

4

2 回答 2

0

缺少依赖项:dbus-python

于 2018-09-10T20:29:15.333 回答
0

尝试这样做:

dbus-run-session -- python -c "import keyring.backends.SecretService as SS; SS.Keyring.priority"

SecretService (Gnome Keyring) 需要一个 DBUS 会话。如果您在无头服务器上运行,则需要在 dbus 会话中运行需要访问密钥环的应用程序(如上所示)。

于 2021-12-12T23:22:37.580 回答