2016-04-08 100 views
1

我连接到我的远程计算机来的AutoLaunch一个DBUS守护进程没有$显示X11:无法通过ssh在python

self.client = paramiko.SSHClient() 
    self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 
    self.client.connect(hostname=ip_address, username=self.user, password=self.password, look_for_keys=False) 

当我发出指令:

chan = self.client.get_transport().open_session(timeout=timeout) 
    chan.request_x11() 
    chan.settimeout(timeout) 
    chan.exec_command(command) 
    stdin = chan.makefile('wb', -1) 
    stdout = chan.makefile('r', -1) 
    stderr = chan.makefile_stderr('r', -1) 
    return stdin, stdout, stderr 

如果我这样做不要使用此行:

chan.request_x11() 

我试着使用:

self.client.exec_command(command) 

但同样的错误

我从标题中的错误消息。当我使用该行时,当从stdout读取时,我会得到一个超时连接。我试过设置

DISPLAY=:0 

什么也没做。我试图通过ssh发送dbus命令。当我通过终端手动连接到ssh时,我可以使用-X或不使用它,并且可以使用我的dbus调用,这并不重要。

回答

0

在没有X11/Display的情况下使用Shell的Dbus。 Dbus需要知道DBUS_SESSION_BUS_ADDRESS。 所以要么你出口这个或出口DISPLAY ...

1)导出DBUS_SESSION_BUS_ADDRESS方法。

第一台启动服务器。 EVAL 'DBUS推出--auto语法' ./server

从服务器ENVIRON(/ proc /进程服务器/ ENVIRON) 你可以得到DBUS_SESSION_BUS_ADDRESS。 在你正在启动客户端程序的shell中导出该值,启动客户端 ./client ... 它应该没有问题。