'Paramiko Error reading SSH protocol banner
I'm having issues handling this error: "Error reading SSH protocol banner" + str(e) paramiko.ssh_exception.SSHException: Error reading SSH protocol banner.
this is the code I'm trying to run:
from netmiko import ConnectHandler
from netmiko.ssh_exception import  NetMikoTimeoutException
from paramiko.ssh_exception import SSHException
ip_list = ['192.168.1.77','192.168.1.73','192.168.1.75','192.168.1.74']
for ip in ip_list:
    cisco = {
        'device_type': 'cisco_ios',
        'host':   ip,
        'username': 'gianluca',
        'password': 'gianluca',
        'secret': 'gianluca',
        "fast_cli": False
    }
    try:
        net_connect = ConnectHandler(**cisco)
    except NetMikoTimeoutException:
        print(f'Machine with ip address {ip} is not reachable')
        continue
    except SSHException:
    
        print(f'Ssh not enabled on Machine with ip address {ip}')
        continue
    except:
        print(f'Oops, something went wrong on the Machine with ip address {ip}!')
        continue
    net_connect.enable()   
    net_connect.send_config_from_file('bbb.txt')
    print(f'Machine with ip address {ip} was configured correctly')
but when I reach a machine that doesn't have ssh enabled I get a large red error message, which is the following:
Exception: Error reading SSH protocol banner
Traceback (most recent call last):
  File "C:\Users\gianluca.platania\AppData\Local\Programs\Thonny\lib\site-packages\paramiko\transport.py", line 2211, in _check_banner
    buf = self.packetizer.readline(timeout)
  File "C:\Users\gianluca.platania\AppData\Local\Programs\Thonny\lib\site-packages\paramiko\packet.py", line 380, in readline
    buf += self._read_timeout(timeout)
  File "C:\Users\gianluca.platania\AppData\Local\Programs\Thonny\lib\site-packages\paramiko\packet.py", line 609, in _read_timeout
    raise EOFError()
EOFError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "C:\Users\gianluca.platania\AppData\Local\Programs\Thonny\lib\site-packages\paramiko\transport.py", line 2039, in run
    self._check_banner()
  File "C:\Users\gianluca.platania\AppData\Local\Programs\Thonny\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
I'm trying to not make this appear handling the exception, but it seems like nothing works. Any idea?
PS: I also get this error on thonny: Library stubs not installed for "paramiko.ssh_exception" (or incompatible with Python 3.7
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source | 
|---|
