Python DBus对象集属性

Python DBus对象集属性,python,dbus,gobject,rhythmbox,Python,Dbus,Gobject,Rhythmbox,我在Python中的Gobject自省方面遇到了问题。 我试图通过DBUS访问Rhythmbox,我可以访问org.mpris.MediaPlayer2.Player中的方法,但我试图为org.mpris.MediaPlayer2.Player的属性设置值,这对我不起作用 from gi.repository import Gio connection = Gio.bus_get_sync(Gio.BusType.SESSION, None) player = Gio.DBusProxy.new

我在Python中的Gobject自省方面遇到了问题。 我试图通过DBUS访问Rhythmbox,我可以访问org.mpris.MediaPlayer2.Player中的方法,但我试图为org.mpris.MediaPlayer2.Player的属性设置值,这对我不起作用

from gi.repository import Gio
connection = Gio.bus_get_sync(Gio.BusType.SESSION, None)
player = Gio.DBusProxy.new_sync(connection, 0, None, 'org.gnome.Rhythmbox3', '/org/mpris/MediaPlayer2', 'org.mpris.MediaPlayer2.Player', None)

properties = Gio.DBusProxy.new_sync(connection, 0, None, 'org.gnome.Rhythmbox3', '/org/mpris/MediaPlayer2', 'org.freedesktop.DBus.Properties', None)
我可以使用类似player.PlayPause()的方法。 当我努力的时候

       properties.Set('org.mpris.MediaPlayer2.Player.rhythmbox', 'Volume', data)
我收到一条错误消息:

Unhandled Error
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/twisted/python/log.py", line 69, in callWithContext
    return context.call({ILogContext: newCtx}, func, *args, **kw)
  File "/usr/lib/python2.7/site-packages/twisted/python/context.py", line 118, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
  File "/usr/lib/python2.7/site-packages/twisted/python/context.py", line 81, in callWithContext
    return func(*args,**kw)
  File "/usr/lib/python2.7/site-packages/twisted/internet/posixbase.py", line 626, in _doReadOrWrite
    why = selectable.doRead()
--- <exception caught here> ---
  File "/usr/lib/python2.7/site-packages/twisted/internet/udp.py", line 147, in doRead
    self.protocol.datagramReceived(data, addr)
  File "RhythmboxDbus.py", line 27, in datagramReceived
    properties.Set('org.mpris.MediaPlayer2.Player.rhythmbox', 'Volume', data)
  File "/usr/lib/python2.7/site-packages/gi/overrides/Gio.py", line 156, in __call__
    arg_variant = GLib.Variant(signature, tuple(args))
  File "/usr/lib/python2.7/site-packages/gi/overrides/GLib.py", line 185, in __new__
    (v, rest_format, _) = creator._create(format_string, [value])
  File "/usr/lib/python2.7/site-packages/gi/overrides/GLib.py", line 68, in _create
    v = constructor(args[0])
  File "/usr/lib/python2.7/site-packages/gi/types.py", line 76, in constructor
    return info.invoke(cls, *args, **kwargs)
exceptions.TypeError: Must be string, not tuple
未处理的错误
回溯(最近一次呼叫最后一次):
callWithContext中的文件“/usr/lib/python2.7/site packages/twisted/python/log.py”,第69行
返回context.call({ILogContext:newCtx},func,*args,**kw)
callWithContext中的文件“/usr/lib/python2.7/site packages/twisted/python/context.py”,第118行
返回self.currentContext().callWithContext(ctx,func,*args,**kw)
callWithContext中的文件“/usr/lib/python2.7/site packages/twisted/python/context.py”,第81行
返回函数(*参数,**kw)
文件“/usr/lib/python2.7/site-packages/twisted/internet/posixbase.py”,第626行,在_-doReadOrWrite中
why=selectable.doRead()
---  ---
文件“/usr/lib/python2.7/site packages/twisted/internet/udp.py”,第147行,在doRead中
self.protocol.datagramReceived(数据,地址)
datagramReceived中第27行的文件“RhythmboxDbus.py”
properties.Set('org.mpris.MediaPlayer2.Player.rhythmbox','Volume',data)
文件“/usr/lib/python2.7/site packages/gi/overrides/Gio.py”,第156行,在调用中__
arg_variant=GLib.variant(签名,元组(args))
文件“/usr/lib/python2.7/site packages/gi/overrides/GLib.py”,第185行,新__
(v,rest_format,_)=创建者。_创建(format_string,[value])
文件“/usr/lib/python2.7/site packages/gi/overrides/GLib.py”,第68行,在创建
v=构造函数(参数[0])
文件“/usr/lib/python2.7/site packages/gi/types.py”,第76行,在构造函数中
return info.invoke(cls、*args、**kwargs)
exceptions.TypeError:必须是字符串,而不是元组

Data是一个字符串,包含0到100之间的数字。该问题与您的问题类似,并且有一个使用
dbus
包的解决方案。您可以将解决方案移植到基于
gi
的解决方案中,这可能会有所帮助。@Small Zane-看起来您是在Twisted应用程序中使用DBus。对于Twisted,您可能需要考虑python dbus的一个替代方案: