2012-12-18 107 views
3

如果失败:paramiko抛出连接失败的错误/异常?

ssh = paramiko.SSHClient() 
ssh.connect(host, username = USER , pkey = MY_KEY, timeout = 2) 

我得到这样一个回溯:

File "<stdin>", line 1, in <module> 
    File "<stdin>", line 7, in bs_process 
    File "/usr/lib/python2.7/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): 
socket.gaierror: [Errno -2] Name or service not known 

我无法弄清楚什么样的/种错误的paramiko抛出坏连接尝试。哪些是异常类,如何导入它们?

+0

我抓住(并重新加注)'BadHostKeyException','AuthenticationException', 'SSHException'和'socket.error'。可能还会有更多... – Ben

+0

@Ben显然,'BadHostKeyException'和'AuthenticationException'是'SSHException'的子类。所以你只需要后者... – glglgl

+0

我以不同的方式处理它们@glglgl ...我可能不需要'SSHException',但它写了一段时间之前我想成为_sure _... – Ben

回答

3

接受的答案有一个断开的链接。为的paramiko文档现在住在:

http://docs.paramiko.org/en/1.15/api/client.html#paramiko.client.SSHClient.connect

它的 “连接” 的方法将引发如下:

BadHostKeyException – if the server’s host key could not be verified 
AuthenticationException – if authentication failed 
SSHException – if there was any other error connecting or establishing an SSH session 
socket.error – if a socket error occurred while connecting 
相关问题