dbus-python variants

Will Thompson will.thompson at collabora.co.uk
Thu Apr 28 04:49:59 PDT 2011


On 28/04/11 07:41, Lukas Hetzenecker wrote:
> Hello,
> 
> I want to transmit the following dict over dbus (using the dbus-python 
> bindings):
> 
> {'name': 'test', 'id': 10} to a method with the signature a{sv}
> 
> But i get the following error: 
> process 8413: Array or variant type requires that type string be written, but 
> end_dict_entry was written. The overall signature expected here was 'a{ss}' 
> and we are on byte 3 of that signature.
> 
> So it doesn't like the different datatype of my dictionary values, but I 
> thought a "variant" can be of any type?
> 
> The dbus-python tutorial states that a variant is "a container which may hold 
> any D-Bus type, including another variant".
> So why does the automatic conversion to dbus types fail for the above 
> dictionary?

Because dbus-python guesses the dictionary type by looking at the first
key-value pair which is 's' and 's' in this case.

You can use dbus.Dictionary({'name': 'test', 'id': 10}, signature='sv')
to explicitly tell it what type the dictionary should have.

-- 
Will


More information about the dbus mailing list