繁体   English   中英

无法通过python中的ssh在没有$ DISPLAY for X11的情况下自动启动dbus-daemon

[英]Unable to autolaunch a dbus-daemon without a $DISPLAY for X11 through ssh in 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调用无所谓。

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

1)导出DBUS_SESSION_BUS_ADDRESS方法。

首次启动服务器。 eval'dbus-launch --auto-syntax'./server

从服务器环境(/ proc / pid-server / environ),您可以获得DBUS_SESSION_BUS_ADDRESS。 在你正在启动客户端程序的shell中导出该值,启动客户端./client ...它应该没有问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM