python脚本中的scp命令不工作

发布于 2025-01-17 10:44:18 字数 818 浏览 0 评论 0原文

我有一个问题好几天了。在我的 Raspberry Pi 上,我转到终端执行以下命令:

scp [email protected]:/home/path/to/file/test.py /home/pi/update/test.py

它工作正常,并且无需密码(因为 ssh-keys)即可将文件从服务器复制到我的本地计算机。

但是:我必须在 python 脚本中执行完全相同的操作:

import os
cmd = 'scp [email protected]:/home/path/to/file/test.py /home/pi/update/test.py'
os.system(cmd)

这不起作用并给出错误

ssh: Could not resolve hostname subdomain.server.com: Temporary failure in name resolution

为什么我会收到此消息,特别是如何解决它?请问有人给个建议吗?我不明白...

I have a problem for several days. On my Raspberry Pi I go to the terminal for executing the following command:

scp [email protected]:/home/path/to/file/test.py /home/pi/update/test.py

It works fine and copies the file from the server without password (because of ssh-keys) to my local machine.

BUT: I have to do exactly the same within a python script:

import os
cmd = 'scp [email protected]:/home/path/to/file/test.py /home/pi/update/test.py'
os.system(cmd)

This doesn't work giving an error

ssh: Could not resolve hostname subdomain.server.com: Temporary failure in name resolution

Why do I get this message and especially how can I solve it? Does anyone give an advice, please? I don't understand it ...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文