python - 未获取 dbus 消息参数

标签 python dbus

我设置了一段读取 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))

关于python - 未获取 dbus 消息参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32092249/

相关文章:

python - 使用 if/else 和 for 循环将项目附加到列表理解中的列表

linux - Bluez D 总线, "StartNotify"与 "AcquireNotify"

使用 D-Bus (qdbus) Send With org.bluez.MediaTransport1 发送 AVRCP 音量更改的蓝牙问题

python - 在 Firebase 托管中使用 Python Google Cloud Function

javascript - 单击按钮并使用 JavaScript(或 jquery)获取同一行中单元格的值

ruby - 调用 ACPI/D-bus 运行 ruby​​ 脚本

c++ - 如何用 QDBus 解析 {String 的字典,{String,Variant}} 的字典?

python - 通过python监控dbus消息

python - 如何在 python 中进行矩阵计算而不进行舍入?

python - 如何将 uirevision 直接添加到 Plotly Dash 中的图形以进行自动更新