Python Forum
I have an issue with Netmiko Error reading SSH protocol banner
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I have an issue with Netmiko Error reading SSH protocol banner
#1
I wrote a code to go through an inventory list of Cisco devices and do some tasks. My problem is because the inventory list is huge, and no guarantee if the device is online or decommissioned, i have to run the code anyway and expect that connection error.

I noticed that when i connect to the device without proxy, it doesn't show this banner error for the offline device.

I'm using Netmiko, but here i'm stuck with this error when the device is offline:

              check1= 0

            try:        #Avoid Timeout & Auth errors and continuo for next switch
                net_connect = ConnectHandler(**switch)
            except (NetMikoTimeoutException, NetMikoAuthenticationException):
                print ('\n' + 'Cannot connect to device: ' + HOST)
                check1= 1
            except paramiko.AuthenticationException:
                print ('\n' + 'AuthenticationException ' + HOST)
                check1= 1
            except paramiko.SSHException as e:
                print ('\n' + 'SSHException' + HOST)
                check1= 1

            except paramiko.ssh_exception.SSHException as e:
                if e.message == 'Error reading SSH protocol banner':
                    print ('\n' + 'SSHException' + HOST)
                check1= 1

            except paramiko.ssh_exception.NoValidConnectionsError as e:
                if e.message == 'Error reading SSH protocol banner':
                    print ('\n' + 'SSHException' + HOST)
                check1= 1

            
            if bool(check1) == False:   #If can connect, then continue... otherwise, skip to next host in the for loop
Then the code when it comes to an offline device, it will give this error:

Error:
Exception (client): Error reading SSH protocol banner Traceback (most recent call last): File "/usr/local/lib/python3.6/site-packages/paramiko/transport.py", line 2270, in _check_banner buf = self.packetizer.readline(timeout) File "/usr/local/lib/python3.6/site-packages/paramiko/packet.py", line 380, in readline buf += self._read_timeout(timeout) File "/usr/local/lib/python3.6/site-packages/paramiko/packet.py", line 622, in _read_timeout raise socket.timeout() socket.timeout During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/lib/python3.6/site-packages/paramiko/transport.py", line 2093, in run self._check_banner() File "/usr/local/lib/python3.6/site-packages/paramiko/transport.py", line 2275, in _check_banner "Error reading SSH protocol banner" + str(e) paramiko.ssh_exception.SSHException: Error reading SSH protocol banner Cannot connect to device: 10.25.44.4
Reply
#2
FYI:
if bool(check1) == False:
can be written
if not check1:
omarhegazy likes this post
Reply
#3
(May-16-2022, 05:30 PM)Larz60+ Wrote: FYI:
if bool(check1) == False:
can be written
if not check1:

Thanks
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  xlwings error when reading a workbook Mishal0488 1 1,126 Aug-01-2023, 02:05 AM
Last Post: deanhystad
  Programming a routing protocol leemao 2 2,190 Jul-13-2021, 05:47 PM
Last Post: leemao
  Netmiko Loop question sc00ter 2 3,332 Oct-24-2020, 10:54 PM
Last Post: sc00ter
  Issue with HX711 reading duckredbeard 0 2,193 Aug-28-2020, 10:00 AM
Last Post: duckredbeard
  Splitting the audio file into smaller packets before transfer using UDP protocol in p MuhammadAli152 0 3,739 May-15-2020, 03:01 PM
Last Post: MuhammadAli152
  Error With Reading Files In Directory And Calculating Values chascp 2 2,454 Feb-15-2020, 01:57 PM
Last Post: chascp
  Sending Advanced Commands with Netmiko rogueakula 1 2,015 Oct-22-2019, 07:54 PM
Last Post: rogueakula
  EOFError: EOF when reading a line - Runtime Error RavCOder 6 9,693 Sep-27-2019, 12:22 PM
Last Post: RavCOder
  Project, Reading Data from a spreadsheet. Error message!! Shafla 1 5,223 Sep-27-2019, 10:44 AM
Last Post: buran
  Reading DBF files from Amazon s3 throwing error - 'int' object has no attribute 'isa abeesm 1 2,930 Sep-22-2019, 05:49 PM
Last Post: ndc85430

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020