没有得到 dbus 消息参数

Not getting dbus message arguments

我设置了一段读取 dbus 消息的代码:

def nf(bus, message):
  print(message)
  args = message.get_args_list()
  for arg in message.get_args_list():
    print("arg:" + arg)

DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()
bus.add_match_string_non_blocking("interface='org.freedesktop.Notifications',eavesdrop='true',member='Notify'")
bus.add_message_filter(nf)
mainloop = gobject.MainLoop()
mainloop.run()

当我启动它时,我收到启动消息 <dbus.lowlevel.SignalMessage path: /org/freedesktop/DBus, iface: org.freedesktop.DBus, member: NameAcquired, dest: :1.215> 和参数 1.215
但是当我用 notify-send 发送消息时,我也收到消息 <dbus.lowlevel.MethodCallMessage path: /org/freedesktop/Notifications, iface: org.freedesktop.Notifications, member: Notify dest: :1.212> 但我没有收到任何参数。当我用 dbus-monitor 尝试这个时,我得到了所有参数。我错过了什么?

出于某种原因,arg 不喜欢与其他内容一起放在打印语句中。似乎 python 不会自动将列表项转换为字符串,就像您只是打印类似 arg[0].

的内容一样

改变

print('arg:' + arg)

print('arg:' + str(arg))

甚至

print('%s %s' % ('arg:', arg))