I am testing how to differentiate between "no connection" and "wrong password" for ssh login. My ssh class is like the following
class SSH(object):
def __init__(self, ip):
self.ip = ip
def connect (self):
try:
connection = pxssh.pxssh()
connection.login(self.ip, "user", "password")
print "success"
return
except pexpect.EOF:
print "no connection"
return
except pxssh.ExceptionPxssh as e:
print "wrong password"
return
But it looks like in some cases even there is no ssh connection or connection timeout (such as ssh to a windows), it still throws the exception of pxssh.ExceptionPxssh
instead of pexpect.EOF
. But in other cases it works fine.
Could anyone give some advice what's the issue and how to fix?