【问题标题】:Unable to autolaunch a dbus-daemon without a $DISPLAY for X11 through ssh in python无法在没有 $DISPLAY 的情况下通过 python 中的 ssh 自动启动 dbus-daemon
【发布时间】:2016-04-08 19:28:18
【问题描述】:

我通过以下方式连接到我的远程计算机:

    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) 

但同样的错误

我从标题中收到错误消息。当我使用这条线时,我在尝试从标准输出读取时得到一个超时连接。我试过设置

DISPLAY=:0

什么也没做。我正在尝试通过 ssh 发送 dbus 命令。当我通过终端手动连接 ssh 时,我可以使用 -X 或不使用它,我可以使用我的 dbus 调用,这没关系。

【问题讨论】:

    标签: python ssh paramiko dbus


    【解决方案1】:

    在没有 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。 在您启动客户端程序的外壳中导出该值, 启动客户端 。/客户 ... 它应该可以正常工作。

    【讨论】:

      猜你喜欢
      • 2015-10-23
      • 2012-01-23
      • 2016-09-14
      • 2018-02-07
      • 1970-01-01
      • 1970-01-01
      • 2016-07-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多