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拋出壞連接嘗試。哪些是異常類,如何導入它們?
我抓住(並重新加註)'BadHostKeyException','AuthenticationException', 'SSHException'和'socket.error'。可能還會有更多... – Ben
@Ben顯然,'BadHostKeyException'和'AuthenticationException'是'SSHException'的子類。所以你只需要後者... – glglgl
我以不同的方式處理它們@glglgl ...我可能不需要'SSHException',但它寫了一段時間之前我想成爲_sure _... – Ben