如果失败:
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为错误的连接尝试抛出了什么样的错误。哪些是异常类,如何导入它们?
接受的答案有一个断开的链接。Paramiko的文档现在位于:
http://docs.paramiko.org/en/1.15/api/client.html#paramiko.client.SSHClient.connect
如果“连接”方法将引发以下问题:
问题在于对ssh.connect()的调用。
在这种情况下,必须指定连接端口。
示例:
ssh.connect(服务器,端口=22,用户名=user,pkey=key)
那对我有用。
您可以从查看API文档开始,查看以异常结尾的所有类:
http://docs.paramiko.org/en/1.15/api/client.html#paramiko.client.SSHClient.connect
然后,您还应该捕获
socket.error
。我想这会给你带来很多东西。socket.gaierror
是socket.error
的一个子类。相关问题 更多 >
编程相关推荐