Signatures For Nested Dictionaries and List of Dictionaries

Mikkel Kamstrup Erlandsen mikkel.kamstrup at canonical.com
Mon Feb 27 00:16:04 PST 2012


On 02/26/2012 12:39 AM, Mystilleef wrote:
> I'm at my wits end and I need your help.
>
> I'm trying to convert a Python Dictionary into a DBus
> Dictionary to stop DBus from whining.
>
> I've tried every possible signature I could come up with
> in the last 12 hours and still no dice. I get the following
> error or similar.
>
> ============================================================
> ERROR:dbus.service:Unable to guess signature for arguments
> (dbus.Dictionary({u'results': {u'albums': [], u'songs': [{u'comment':
> u'', u'rating': 5, u'lastPlayed': 1329804001860872L, u'disc': 0,
> u'composer': u'', u'year': 2011, u'id':
> u'4c2aa2f4-44cd-37ad-8327-b14de16d492e', u'album': u'', u'title':
> u'Neverland', u'track': 1, u'albumArtist': u'J Cole', u'type': 2,
> u'titleNorm': u'neverland', u'deleted': False, u'albumArtistNorm': u'j
> cole', u'totalTracks': 0, u'beatsPerMinute': 0, u'genre': u'',
> u'playCount': 14, u'creationDate': 1318054682121584L, u'name':
> u'Neverland', u'albumNorm': u'', u'artist': u'J Cole', u'url': u'',
> u'totalDiscs': 0, u'durationMillis': 223000, u'artistNorm': u'j
> cole'}], u'artists': []}}, signature=None),):<type
> 'exceptions.ValueError'>: Unable to guess signature from an empty list
> org.freedesktop.DBus.Python.ValueError: Traceback (most recent call last):
>    File "/usr/lib/python2.7/site-packages/dbus/service.py", line 745,
> in _message_cb
>      _method_reply_return(connection, message, method_name, signature, *retval)
>    File "/usr/lib/python2.7/site-packages/dbus/service.py", line 257,
> in _method_reply_return
>      signature = reply.guess_signature(retval) + ' (guessed)'
> ValueError: Unable to guess signature from an empty list
> ============================================================
>
> I've attempted the following:
>
> 	dbus.Dictionary(dictionary, signature="sv")
> 	dbus.Dictionary(dictionary, signature="(sv)")
> 	dbus.Dictionary(dictionary, signature="sa{sv}")
> 	dbus.Dictionary(dictionary, signature="sa{sa(sv)}")
> 	dbus.Dictionary(dictionary, signature="sa{sa{sv}}")
>
> and so on to no avail. I've attempted all variant_levels and
> failed again. I've read the docs, tried to find sources with
> complicated signatures and ransacked the Interwebz. Still
> nothin. I'm just not smart enough to figure it out myself.
> So I need your help, any help is appreciated.

By the looks of it you're trying to send a generic dict (which has 
signature 'a{sv}'). The fact that some values may be lists (and others 
strings, new dicts, or ints, etc) can not be expressed in the type 
signature other that the 'v' we already have in there for the values.

 From the error message 'Unable to guess signature from an empty list' 
it looks like the problem is the empty list for the 'artists' key. 
Assuming that this is an empty lists of strings you need to create it as 
dbus.Array(signature="s") and then add that your dict instead of a 
normal [] instance.

Good luck. Cheers,

Mikkel


More information about the dbus mailing list