Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what error/exception does paramiko throw for failed connects?

If this fails:

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

I get a traceback like:

  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

I cant figure what kind/kinds of errors Paramiko throws for bad connect attempts. Which are the exception classes and how can I import them?

like image 879
Jesvin Jose Avatar asked Jan 14 '23 17:01

Jesvin Jose


1 Answers

You can start by looking at the API documentation, for all classes ending in Exception:

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

Then, you should also catch socket.error. I think that will get you pretty much everything. socket.gaierror is a subclass of socket.error, for example.

like image 142
djc Avatar answered Jan 19 '23 00:01

djc