我尝试用python从klipper总线调用方法。但我做不到。以下是我的尝试:

>>> import dbus
>>> bus = dbus.SessionBus()
>>> proxy = bus.get_object("org.kde.klipper","/org/kde/klipper")
>>> print proxy
<ProxyObject wrapping <dbus._dbus.SessionBus (session) at 0x7fc249da3bf0> :1.67 /org/kde/klipper at 0x7fc249dc16d0>
>>> iface = dbus.Interface(proxy,"org.kde.klipper.klipper")
>>> print iface
<Interface <ProxyObject wrapping <dbus._dbus.SessionBus (session) at 0x7fc249da3bf0> :1.67 /org/kde/klipper at 0x7fc249dc16d0> implementing 'org.kde.klipper.klipper' at 0x7fc249dc1790>
>>> print iface.getClipboardContents()
ERROR:dbus.proxies:Introspect error on :1.67:/org/kde/klipper: dbus.exceptions.DBusException: org.freedesktop.DBus.Error.UnknownObject: No such object path '/org/kde/klipper'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/site-packages/dbus/proxies.py", line 68, in __call__
    return self._proxy_method(*args, **keywords)
  File "/usr/lib/python2.6/site-packages/dbus/proxies.py", line 140, in __call__
    **keywords)
  File "/usr/lib/python2.6/site-packages/dbus/connection.py", line 622, in call_blocking
    message, timeout)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.UnknownObject: No such object path '/org/kde/klipper'

如您所见,它同时设置代理和接口。但是我不能通过这个接口调用方法。
我能做什么?我做错什么了?
编辑已解决:
当我看“qdbusviewer”时,我看到了飞利浦的确切路径。
所以改变
>> proxy = bus.get_object("org.kde.klipper","/org/kde/klipper")

这句话的意思是:
>>> proxy = bus.get_object("org.kde.klipper","/klipper")

解决问题。
我希望这篇文章能帮助一些人

最佳答案

经过一番尝试,我发现了错误:
>>> proxy = bus.get_object("org.kde.klipper","/org/kde/klipper")
必须是:
>>> proxy = bus.get_object("org.kde.klipper","/klipper")
这解决了问题

关于python - 无法使用python调用dbus中的klipper方法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5156549/

10-11 18:20