【问题标题】:Socket error when connecting to remote machine with Python使用 Python 连接到远程机器时出现套接字错误
【发布时间】:2012-09-14 12:06:30
【问题描述】:

我正在使用 Python 的 paramiko 包连接到远程 Unix 机器。我写了这段代码:

import paramiko
import sys
import os
import os.path
passwd = "XXX"
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect("173.15.13.28", "root", password=passwd)
stdin, stdout, stderr = ssh.exec_command('ls')
x = stdout.readlines()
print x
for line in x:
   print line
ssh.close()

执行后出现此错误:

   Traceback (most recent call last):
    File "<pyshell#9>", line 1, in <module>
      ssh.connect("173.15.13.28", "root", password="--------")
    File "C:\Python27\lib\site-packages\paramiko\client.py", line 282, in connect
      for (family, socktype, proto, canonname, sockaddr) in socket.getaddrinfo(hostname, port,socket.AF_UNSPEC, socket.SOCK_STREAM):
    gaierror: [Errno 10109] getaddrinfo failed

我不知道是什么问题。

【问题讨论】:

  • 您现在应该更改密码了。

标签: python unix ssh paramiko


【解决方案1】:

connect() 方法的第二个参数是端口号,默认为 22。您将“root”放在那里,这是行不通的。使用关键字参数username="root"。也就是说,试试这个:

ssh.connect("173.15.13.28", username="root", password=passwd)

另见:python paramiko, getaddrinfo error when trying to establish an SSH connection

【讨论】:

    猜你喜欢
    • 2011-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-17
    • 2019-06-05
    • 2019-06-25
    相关资源
    最近更新 更多