gpt4 book ai didi

python - 使用 Paramiko、Python 时不支持 Errno -8 Servname

转载 作者:行者123 更新时间:2023-11-28 19:24:37 25 4
gpt4 key购买 nike

我正在尝试通过 Python 脚本通过 SSH 连接到服务器。目前我正在试用 paramiko。我在客户端和服务器之间设置了一个公钥,所以我不需要密码。我目前正在使用以下代码:

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

ssh.connect('192.168.56.102', 'oracle', None, '~/.ssh/id_rsa')
stdin, stdout, stderr = ssh.exec_command('ls')

但是在运行时出现错误

[Errno -8] Servname not supported for ai_socktype

有什么帮助吗?

最佳答案

您可以只指定参数。不需要添加端口号(如果可以使用默认端口号)。

来自connect的定义,您的示例将如下所示:

ssh.connect('192.168.56.102', username='oracle', password=None, key_filename='~/.ssh/id_rsa')

关于python - 使用 Paramiko、Python 时不支持 Errno -8 Servname,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16211087/

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