I want to publish a python object on a session bus, using pydbus and python 2.7. I'm new to pydbus, so I stick to the example and did the tutorial. However, I did not manage to launch a simply test server with pydbus.
I wrote a simple class, with only one method, which returns a string. I specified an interface and created an event loop.
code:
from pydbus import SessionBus
from gi.repository import GObject
loop = GObject.MainLoop()
class Testclass(object):
"""
<node>
<interface name='org.philipp.DBUSTutorial'>
<method name='helloworld'>
<arg type='s' name='reply' direction='out'/>
</method>
</interface>
</node>
"""
def helloworld():
return "Hello World"
bus = SessionBus()
bus.publish("org.philipp.DBUSTutorial", Testclass())
loop.run()
After executing the script it throws an error.
error message:
Traceback (most recent call last):
File "test.py", line 24, in <module>
bus.publish("org.philipp.DBUSTutorial", Testclass())
File "/usr/local/lib/python2.7/dist-packages/pydbus/publication.py", line 33, in publish
return Publication(self, bus_name, *objects)
File "/usr/local/lib/python2.7/dist-packages/pydbus/publication.py", line 26, in __init__
self._at_exit(bus.register_object(path, object, node_info).__exit__)
File "/usr/local/lib/python2.7/dist-packages/pydbus/registration.py", line 123, in register_object
return ObjectRegistration(self.con, path, interfaces, wrapper, own_wrapper=True)
File "/usr/local/lib/python2.7/dist-packages/pydbus/registration.py", line 103, in __init__
ids = [con.register_object(path, interface, wrapper.call_method, wrapper.get_property, wrapper.set_property) for interface in interfaces]
TypeError: argument vtable: Expected Gio.DBusInterfaceVTable, but got pydbus.registration.instancemethod
What am I doing wrong? It would be great, if somebody could help me to find my mistake.
As described in Readme: "Since 0.5, it supports publishing objects on the bus - however this requires GLib 2.46 or newer."
Unfortunately there is no way to publish objects with older GLib.