Не могу разобраться с перехватом исключений.
Код
def ssh_connect(host, username, password): ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) try: ssh.connect(host, port=22, username=username, password=password) except paramiko.ssh_exception.BadAuthenticationType: print(logbadhost + host + " is not accept passwors") logger.log(3, logbadhost + host + " is not accept passwors") return 2 except paramiko.ssh_exception.AuthenticationException: logger.log(2, logbadpass + username + "@" + host + ":" + password) return 1 except paramiko.ssh_exception.SSHException: logger.log(3, logbadhost + host + " is ebnytii kakoito") return 2 except socket.timeout: logger.log(3, logbadhost + host + " is down") return 2 except socket.error as e: # print(e) return except ConnectionRefusedError as e: # print(e) logger.log(3, logbadhost + host + " is ebnytii kakoito") return 2 except EOFError as e: # print(e) logger.log(3, logbadhost + host + " is ebnytii kakoito") return 2 except: return 2 else: print(loggoodpass + username + "@" + host + ":" + password) logger.log(4, loggoodpass + username + "@" + host + ":" + password) return 0 finally: ssh.close()
Вроде в try обернул, но все равно пишет
Exception: Error reading SSH protocol banner Bad file descriptor
Traceback (most recent call last):
File “/usr/local/lib/python3.4/dist-packages/paramiko/transport.py”, line 1707, in _check_banner
buf = self.packetizer.readline(timeout)
File “/usr/local/lib/python3.4/dist-packages/paramiko/packet.py”, line 281, in readline
buf += self._read_timeout(timeout)
File “/usr/local/lib/python3.4/dist-packages/paramiko/packet.py”, line 434, in _read_timeout
x = self.__socket.recv(128)
OSError: Bad file descriptor
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/usr/local/lib/python3.4/dist-packages/paramiko/transport.py”, line 1584, in run
self._check_banner()
File “/usr/local/lib/python3.4/dist-packages/paramiko/transport.py”, line 1711, in _check_banner
raise SSHException('Error reading SSH protocol banner' + str(e))
paramiko.ssh_exception.SSHException: Error reading SSH protocol banner Bad file descriptor
Заранее спасибо за помощь!