【问题标题】:Not getting dbus message arguments没有得到 dbus 消息参数
【发布时间】:2015-08-19 09:56:28
【问题描述】:

我已经设置了一段读取 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 尝试这个时,我得到了所有的论点。我错过了什么?

【问题讨论】:

    标签: python dbus


    【解决方案1】:

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

    改变

    print('arg:' + arg)
    

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

    甚至

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

    【讨论】:

      猜你喜欢
      • 2019-10-23
      • 2022-01-06
      • 2015-09-07
      • 1970-01-01
      • 1970-01-01
      • 2017-09-24
      • 2012-07-17
      • 1970-01-01
      • 2017-11-19
      相关资源
      最近更新 更多