红联Linux门户
Linux帮助

org.freedesktop.DBus.Error.AccessDenied解决办法

发布时间:2017-03-01 12:04:13来源:linux网站作者:FoxBryant
操作平台:Ubuntu
 
运行自己用Python写的dbus服务时,出现如下错误:
Traceback (most recent call last):
File "./test.py", line 87, in <module>
object = DeviceObject()
File "./test.py", line 37, in __init__
bus_name = dbus.service.BusName(Bus_Name,bus=dbus.SystemBus())
File "/usr/lib/python2.7/dist-packages/dbus/service.py", line 131, in __new__
retval = bus.request_name(name, name_flags)
File "/usr/lib/python2.7/dist-packages/dbus/bus.py", line 303, in request_name
'su', (name, flags))
File "/usr/lib/python2.7/dist-packages/dbus/connection.py", line 651, in call_blocking
message, timeout)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.AccessDenied: Connection ":1.92" is not allowed to own the service "com.foxbryant.demo" due to security policies in the configuration file
 
解决方法:
在/etc/dbus-1/system.d/目录下创建com.foxbryant.demo.conf (名称随意,以.conf结尾即可) 内容如下:
<!DOCTYPE busconfig PUBLIC
"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
<!-- Only root and devel can own the service -->
<policy user="root">
<allow own="com.foxbryant.demo"/>
<allow send_destination="com.foxbryant.demo"/>
<allow send_interface="com.foxbryant.demo"/>
</policy>
<policy user="foxbryant">
<allow own="com.foxbryant.demo"/>
<allow send_destination="com.foxbryant.demo"/>
<allow send_interface="com.foxbryant.demo"/>
</policy>
</busconfig>
 
本文永久更新地址:http://www.linuxdiyf.com/linux/28803.html