Why cannot call method in org.freedesktop.NetworkManager with dbus in Python?
dbus, python, ubuntu
Solution
In your command line example you're asking for the system bus:
dbus-send --system ...
In your Python code, you're asking for the session bus:
bus = dbus.SessionBus()
If you try the request over the system bus, I think you'll find that it works:
>>> import dbus
>>> bus = dbus.SystemBus()
>>> obj = bus.get_object('org.freedesktop.NetworkManager', '/org/freedesktop/NetworkManager')
>>> t = dbus.Interface(obj, "org.freedesktop.NetworkManager")
>>> t.GetDevices()
dbus.Array([dbus.ObjectPath('/org/freedesktop/NetworkManager/Devices/0'), dbus.ObjectPath('/org/freedesktop/NetworkManager/Devices/1')], signature=dbus.Signature('o'))
>>>
Problem
I tried the code below in interactive python shell and got the follow error in line 3 of code, using D-Feet I see that path and interface exists in bus, and with the command dbus-send I able to get the devices, see in end of this message. Why not work with this code in python? PS: I using ubuntu 12.04, tried too in ubuntu 11, same problem. Code: ``` import dbus bus = dbus.SessionBus() obj = bus.get_object('org.freedesktop.NetworkManager', '/org/freedesktop/NetworkManager') t = dbus.Interface(obj, "org.freedesktop.NetworkManager") t.GetDevices() ``` Output error entering line 3 of code: ``` Traceback (most recent call last): File "<input>", line 1, in <module> File "/usr/lib/pymodules/python2.7/dbus/bus.py", line 244, in get_object follow_name_owner_changes=follow_name_owner_changes) File "/usr/lib/pymodules/python2.7/dbus/proxies.py", line 241, in __init__ self._named_service = conn.activate_name_owner(bus_name) File "/usr/lib/pymodules/python2.7/dbus/bus.py", line 183, in activate_name_owner self.start_service_by_name(bus_name) File "/usr/lib/pymodules/python2.7/dbus/bus.py", line 281, in start_service_by_name 'su', (bus_name, flags))) File "/usr/lib/pymodules/python2.7/dbus/connection.py", line 630, in call_blocking message, timeout) DBusException: org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.NetworkManager was not provided by any .service files ``` Shell command that work: ``` dbus-send --system --print-reply --reply-timeout=2000 --type=method_call --dest=org.freedesktop.NetworkManager /org/freedesktop/NetworkManager org.freedesktop.NetworkManager.GetDevices ``` Output: ``` method return sender=:1.2 -> dest=:1.69 reply_serial=2 array [ object path "/org/freedesktop/NetworkManager/Devices/0" ] ``` This is just a example, I wish to know why don't work, If I change line 3 to (note the DBus name in first parameter): ``` obj = bus.get_object('org.freedesktop.DBus', '/org/freedesktop/NetworkManager') ``` the error don't occur, but in this interface the method GetDevices doesn't exists.