【发布时间】:2020-01-08 11:53:23
【问题描述】:
我有 python 脚本(我们称之为 script1.py),它使用 execnet 模块在其他机器上远程启动其他脚本(script2.py)。它的重要部分如下所示:
import script2
host = "name@ip"
gw = execnet.makegateway("ssh={}".format(host))
channel = gw.remote_exec(script2)
它在做什么无关紧要,因为当我在终端中启动它时,它工作得非常好。现在我尝试通过 Flask API 启动它。我正在使用 subprocess 模块通过脚本生成新进程(与不需要连接到另一台机器的任何其他脚本完美配合)。基本上它应该是这样的:
发送启动脚本的请求 -> 使用 script1.py 生成子进程 -> 在 script1.py 中导入 script2 并使用 execnet 在其他机器上启动它
当我这样做时,我得到一个错误:
ssh_askpass: exec(/usr/bin/ssh-askpass): No such file or directory
Permission denied, please try again.
ssh_askpass: exec(/usr/bin/ssh-askpass): No such file or directory
Permission denied, please try again.
ssh_askpass: exec(/usr/bin/ssh-askpass): No such file or directory
Permission denied (publickey,password).
Traceback (most recent call last): File "/home/ubuntu/script1.py", line 23, in <module>
gw = execnet.makegateway("ssh={}".format(host)) File "/usr/local/lib/python2.7/dist-packages/execnet/multi.py",
line 128, in makegateway gw = gateway_bootstrap.bootstrap(io, spec)
File "/usr/local/lib/python2.7/dist-packages/execnet/gateway_bootstrap.py",
line 98, in bootstrap bootstrap_exec(io, spec) File "/usr/local/lib/python2.7/dist-packages/execnet/gateway_bootstrap.py",
line 50, in bootstrap_exec raise HostNotFound(io.remoteaddress) execnet.gateway_bootstrap.HostNotFound: remote@10.10.1.2
奇怪的是,我可以在 linux 终端中做到这一点,但不能通过 API 将它作为子进程启动。有谁知道为什么它不起作用?
【问题讨论】:
-
从终端连接时,需要密码吗?
-
是的,它要求我输入密码
标签: python linux python-2.7