我正在制作一个python应用程序,它有一个需要根权限的方法。在https://www.freedesktop.org/software/polkit/docs/0.105/polkit-apps.html中,我找到了示例2。通过下面代码的python版本的D-Bus访问权限,我执行了它,我认为输入密码后我可以获得根权限,但我仍然在我的应用程序上获得“拒绝许可”。This是我试图连接的函数
import dbus
bus = dbus.SystemBus()
proxy = bus.get_object('org.freedesktop.PolicyKit1', '/org/freedesktop/PolicyKit1/Authority')
authority = dbus.Interface(proxy, dbus_interface='org.freedesktop.PolicyKit1.Authority')
system_bus_name = bus.get_unique_name()
subject = ('system-bus-name', {'name' : system_bus_name})
action_id = 'org.freedesktop.policykit.exec'
details = {}
flags = 1 # AllowUserInteraction flag
cancellation_id = '' # No cancellation id
result = authority.CheckAuthorization(subject, action_id, details, flags, cancellation_id)
print result发布于 2017-01-05 05:23:12
在您引用的python代码中,result表示成功还是失败?如果失败,您需要首先找出bus、proxy、authority和system_bus_name的返回值,从而缩小错误范围。如果它成功了,您需要检查如何使用result。
https://stackoverflow.com/questions/41177874
复制相似问题