dbus-python variants

Lukas Hetzenecker lukas.hetzenecker at gmail.com
Fri Apr 29 02:36:30 PDT 2011


Thanks, this looks like an easy solution. 

I feared that I had to use dbus.String as value (and set the variant_level), 
which would have been much more complicated to implement.

Lukas

Am Donnerstag, 28. April 2011, 12:49:59 schrieb Will Thompson:
> 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.


More information about the dbus mailing list