我写了一个简单的 python 程序来播放和暂停女妖音乐播放器。虽然它在我自己的机器上工作,但我无法在连接到同一路由器 (LAN) 的远程计算机上执行此操作。我编辑了远程机器的 session.conf,添加了这一行:
<listen>tcp:host=localhost,port=12434</listen>
这是我的程序:
import dbus
bus_obj=dbus.bus.BusConnection("tcp:host=localhost,port=12434")
proxy_object=bus_obj.get_object('org.bansheeproject.Banshee',
'/org/bansheeproject/Banshee/PlayerEngine')
playerengine_iface=dbus.Interface(proxy_object,
dbus_interface='org.bansheeproject.Banshee.PlayerEngine')
var=0
while (var!="3"):
var=raw_input("\nPress\n1 to play\n2 to pause\n3 to exit\n")
if var=="1":
print "playing..."
playerengine_iface.Play()
elif var=="2":
print "pausing"
playerengine_iface.Pause()
这就是我尝试执行它时得到的
Traceback (most recent call last):
File "dbus3.py", line 4, in <module>
bus_obj=dbus.bus.BusConnection("tcp:host=localhost,port=12434")
File "/usr/lib/python2.7/dist-packages/dbus/bus.py", line 125, in __new__
bus = cls._new_for_bus(address_or_type, mainloop=mainloop)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NoServer: Failed to connect to socket "localhost:12434" Connection refused
我在这里做错了什么?我应该编辑 /usr/lib/python2.7/dist-packages/dbus/bus.py
更新:
好的,这是我添加时的交易
<listen>tcp:host=192.168.1.7,port=12434</listen>
到/etc/dbus-1/session.conf,然后重新启动,希望它会在重新启动时开始监听,它永远不会启动。它卡在加载屏幕上,偶尔会出现带有以下文本的黑屏:
Pulseaudio Configured For Per-user Sessions Saned Disabled;edit/etc/default/saned
所以,当我去 ctrl+alt+f1 时,将 session.conf 更改为原始状态并重新启动,它可以正常启动。
那是怎么回事?如何让 dbus 守护进程监听 tcp 连接,而不会遇到问题?