gpt4 book ai didi

python - Python shell 和程序中的不同行为

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:56:23 26 4
gpt4 key购买 nike

我正在使用 subprocess.Popen 来实例化 ssh-agent,添加 key 并将 git 存储库推送到远程。为此,我使用 && 将它们串在一起。我使用的代码是

subprocess.Popen("eval $(ssh-agent) && ssh-add /root/.ssh/test_rsa && git push target HEAD", shell=True)

当我将其作为 .py 文件运行时,系统会提示我输入 key 的密码。这似乎在我得到的时候起作用。

身份已添加:/root/.ssh/test_rsa (/root/.ssh/test_rsa)

但是当它尝试将存储库推送到远程时,会发生错误。

ssh: connect to host ***.***.***.*** port 22: Connection refused
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

但是,如果我只是在交互式 shell 中运行相同的命令,它就可以工作。是什么导致了这种行为差异,我该怎么做才能解决这个问题?

最佳答案

git 服务器位于脚本中较早启动的 aws 实例上。有一项检查以确保它正在运行,但 aws 似乎在引导开始后报告实例正在运行。这意味着实例运行的时间很短,但 ssh 守护进程不存在。因为脚本非常快地开始尝试推送,所以它落在这个时间段内并且服务器拒绝了它的连接尝试。当我在交互式 shell 中尝试任何操作时,该实例运行的时间足够长,可以正常工作。

简而言之,aws 表示实例在操作系统启动服务之前正在运行。

关于python - Python shell 和程序中的不同行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25661767/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com