Search code examples
linuxpython-2.7dbus

Python DBus Return Empty List


I have a Python 2.7 DBus method that returns a list of strings. The method works when the list is not empty. When it is empty, an exception is thrown which states "Unable to guess signature from an empty list".

Here is the method:

@dbus.service.method('blecnx.comp.com.control', signature='as')
def getSlaveList(self):
    global connectedSlaves
    print("Interface:getSlaveList() getSlaveList called - length is: %s" % (len(connectedSlaves)))
    if len(connectedSlaves) == 0:
        return dbus.Array(dbus.Array([], signature='as'))
    else:
        return connectedSlaves

Here is the exception:

ERROR:dbus.service:Unable to guess signature for arguments (dbus.Array([], signature=None),): <type 'exceptions.ValueError'>: Unable to guess signature from an empty list

I've tried to update the signature of the DBus method to explicitly state it is an array of strings, but it did not help.

How can I make sure the method does not throw an exception with an empty list?


Solution

  • Turns out you can't just specify "signature='as'" - it has to be "out_signature='as'".

    Now it works.