1

我正在尝试制作一个脚本来在我的 USB 记忆棒连接时启动我的自定义脚本。我在这里找到了不错的 python 脚本,但是当它调用GetAllProperties()方法时出现异常:

错误:dbus.connection:D-Bus 信号处理程序中的异常:
回溯(最近一次调用最后一次):
文件“/usr/lib/python2.7/site-packages/dbus/connection.py”,第 214 行,在maybe_handle_message
self._handler(*args, **kwargs)
文件“./hal-automount”,第 31 行,在 device_added
属性 = self.udi_to_device(udi).GetAllProperties()
文件“/usr/lib/python2.7/site- packages/dbus/proxies.py”,第 68 行,在 __call__ 中
返回 self._proxy_method(*args, **keywords)
文件“/usr/lib/python2.7/site-packages/dbus/proxies.py”,第 140 行,在 __call__
**keywords)
文件“/usr/lib/python2.7/site-packages/dbus/connection.py”,第 630 行,在 call_blocking
消息中,超时)
DBusException: org.freedesktop.DBus.Error.AccessDenied: 拒绝发送消息,3 个匹配规则;type="method_call", sender=":1.39539" (uid=0 pid=9527 comm="python) interface="(unset)" member="getAllProperties" error name="(unset)" requested_reply=0 destination=" :1.8" (uid=0 pid=3039 comm="/usr/sbin/hald))

操作系统:openSuSE 11.4

我以前没有使用 DBus,你能告诉我有什么问题吗?谢谢。

4

1 回答 1

2

由于访问策略,您的 DBus 方法调用失败。这可能是因为您调用了一个方法而没有指定任何接口。看起来像您尝试使用的脚本中的错误(应始终通过接口调用 DBus 方法)。

尝试更换:

def udi_to_device(self, udi):
    return self.bus.get_object("org.freedesktop.Hal", udi)

和:

def udi_to_device(self, udi):
    obj = self.bus.get_object("org.freedesktop.Hal", udi)
    return dbus.Interface(obj, dbus_interface='org.freedesktop.Hal.Device')

顺便说一句:HAL 现在已经过时了,您可能应该切换到 udisk。请参阅http://www.freedesktop.org/wiki/Software/hal

于 2011-10-31T09:41:12.960 回答