使用paramiko的时候捕获异常没有效果
try:
client.connect(hostname='192.168.10.21', port=22, username='root', password='eaecd231')
except paramiko.ssh_exception.AuthenticationException:
print('password error')
except (ConnectionResetError,paramiko.ssh_exception.SSHException):
print('connect error')
但最后还是有报异常
Exception: Error reading SSH protocol banner[WinError 10054] 远程主机强迫关闭了一个现有的连接。Traceback (most recent call last):
File "C:\Users\GreatWall\AppData\Local\Programs\Python\Python36\lib\site-packages\paramiko\transport.py", line 2211, in _check_banner
buf = self.packetizer.readline(timeout)
File "C:\Users\GreatWall\AppData\Local\Programs\Python\Python36\lib\site-packages\paramiko\packet.py", line 380, in readline
buf += self._read_timeout(timeout)
File "C:\Users\GreatWall\AppData\Local\Programs\Python\Python36\lib\site-packages\paramiko\packet.py", line 607, in _read_timeout
x = self.__socket.recv(128)
ConnectionResetError: [WinError 10054] 远程主机强迫关闭了一个现有的连接。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\GreatWall\AppData\Local\Programs\Python\Python36\lib\site-packages\paramiko\transport.py", line 2039, in run
self._check_banner()
File "C:\Users\GreatWall\AppData\Local\Programs\Python\Python36\lib\site-packages\paramiko\transport.py", line 2216, in _check_banner
"Error reading SSH protocol banner" + str(e)
paramiko.ssh_exception.SSHException: Error reading SSH protocol banner[WinError 10054] 远程主机强迫关闭了一个现有的连接。
connect error
以上是 使用paramiko的时候捕获异常没有效果 的全部内容, 来源链接: utcz.com/a/161329.html