Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 903
PhilBot Avatar asked Apr 28 '26 13:04

PhilBot


1 Answers

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

Now it works.

like image 55
PhilBot Avatar answered Apr 30 '26 05:04

PhilBot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!