我正在尝试通过 Python 中的 DBus 获取 VPN 连接的状态。
这是我的代码:
name="testVPN"
proxy = dbus.SystemBus().get_object('org.freedesktop.NetworkManagerUserSettings', '/org/freedesktop/NetworkManagerSettings')
iface = dbus.Interface(proxy, 'org.freedesktop.NetworkManagerSettings')
connections = iface.ListConnections()
for connection in connections:
proxy = dbus.SystemBus().get_object('org.freedesktop.NetworkManagerUserSettings', connection)
iface = dbus.Interface(proxy, 'org.freedesktop.NetworkManagerSettings.Connection')
con_settings = iface.GetSettings()['connection']
if con_settings['type'] == 'vpn' and con_settings['id'] == name:
state=dbus.Interface(proxy, 'org.freedesktop.DBus.Properties').Get('org.freedesktop.NetworkManager.VPN.Connection', 'VpnState')
这会正确找到 VPN 连接,但在最后一行(尝试获取VpnState
属性时)会引发此异常:
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.AccessDenied: Rejected send message, 1 matched rules; type="method_call", sender=":1.169" (uid=0 pid=20580 comm="python) interface="org.freedesktop.DBus.Properties" member="Get" error name="(unset)" requested_reply=0 destination=":1.36" (uid=1000 pid=3457 comm="nm-applet))
问题是什么?
谢谢