问题
I'm trying to make a dbus call using python3.4 and pyqt5.4 to a java-written daemon, the signature of the daemon for the method I'm calling is asa{sv}
The call I'm doing is
fpiudaemon = QDBusInterface("it.libersoft.FirmapiuDInterface", "/it/libersoft/FirmapiuD", interface='it.libersoft.FirmapiuDInterface' , parent=None)
result = fpiudaemon.call('sign',filepath,options)
Where
print (filepath) -> ['/home/svalo/programmi/devel/pythondeps']
print (options) -> {'pin': '12345678', 'outdir': '/home/svalo/programmi/devel/firmapiu-gui'}
print(type(filepath)) -> <class 'list'>
print(type(options)) -> <class 'dict'>
However when I monitor dbus what I get is
method call sender=:1.242 -> dest=it.libersoft.FirmapiuDInterface serial=67 path=/it/libersoft/FirmapiuD; interface=it.libersoft.FirmapiuDInterface; member=sign array [ variant string "/home/svalo/programmi/devel/firmapiu-gui/pythondeps" ] array [ dict entry( string "outdir" variant string "/home/svalo/programmi/devel/firmapiu-gui" ) dict entry( string "pin" variant string "12345678" ) ]
What i'd like to get is
method call sender=:1.242 -> dest=it.libersoft.FirmapiuDInterface serial=67 path=/it/libersoft/FirmapiuD; interface=it.libersoft.FirmapiuDInterface; member=sign array [ string "/home/svalo/programmi/devel/libersoft/firmapiu-gui/pythondeps" ] array [ dict entry( string "outdir" variant string "/home/svalo/programmi/devel/libersoft/firmapiu-gui" ) dict entry( string "pin" variant string "12345678" ) ]
That is I expect python to send an array of strings and instead it sends an array of variants containing strings.
The daemon devel wrote a simple client in java and it works honoring the signature
What am I missing here?
回答1:
According to the dbus-spec, the string-type is defined as follows:
STRING 115 (ASCII 's') UTF-8 string (must be valid UTF-8). Must be nul terminated and contain no other nul bytes.
Which seems to imply that you should pass a UTF-8 encoded bytes object, rather than a unicode object.
EDIT:
You might need to pass this as a QByteArray
:
QtCore.QByteArray(unicode_string.encode('utf-8'))
回答2:
5 years later, an answer appears!
You can specify the type signature of a dbus argument with QDbusArgument
. Here's an example:
filepath = QDBusArgument()
filepath.add(['/home/svalo/programmi/devel/pythondeps'], QMetaType.QStringList)
result = fpiudaemon.call('sign',filepath,options)
Obviously make sure that your data can be converted directly into the type you specified.
来源:https://stackoverflow.com/questions/28075484/how-to-pass-an-array-of-string-to-dbus-in-pyqt5