Netmiko: Juniper disable_paging fails due to cmd_verify

Created on 10 May 2020  路  8Comments  路  Source: ktbyers/netmiko

Hi,

I am new to Netmiko and have been trying to create a script to login into multiple devices in production and execute some show commands from a file using send_command(). I am iterating over the show comamnds in the file and saving the output to a text file using a 'for' loop. I don't have any issues when running the script for Cisco IOS-XR devices but I get the NetmikoTimeoutException when trying to run the script on some Juniper devices (basically it works for some Juniper devices and for some it does not). All the Juniper devices in my network are the same chassis but the ones for which the script is not working have much more config than the others. I suspect it is the large output that is causing this exception but I am not sure (just getting the running config from these devices takes 3-5 minutes). Please find the output from this exception below.

Thank you in advance.

Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32lib\site-packages\paramiko\channel.py", line 699, in recv
out = self.in_buffer.read(nbytes, self.timeout)
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32lib\site-packages\paramiko\buffered_pipe.py", line 164, in read
raise PipeTimeout()
paramiko.buffered_pipe.PipeTimeout

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32lib\site-packages\netmiko\base_connection.py", line 550, in _read_channel_expect
new_data = self.remote_conn.recv(MAX_BUFFER)
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32lib\site-packages\paramiko\channel.py", line 701, in recv
raise socket.timeout()
socket.timeout

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32lib\threading.py", line 870, in run
self._target(self._args, self._kwargs)
File "D:\Python\script\presnaps_juniper.py", line 76, in ssh_connection
session = ConnectHandler(
devices)
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32lib\site-packages\netmiko\ssh_dispatcher.py", line 259, in ConnectHandler
return ConnectionClass(
args, *kwargs)
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32lib\site-packages\netmiko\base_connection.py", line 327, in __init__
self._open()
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32lib\site-packages\netmiko\base_connection.py", line 333, in _open
self._try_session_preparation()
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32lib\site-packages\netmiko\base_connection.py", line 756, in _try_session_preparation
self.session_preparation()
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32lib\site-packages\netmiko\juniper\juniper.py", line 27, in session_preparation
self.disable_paging(command="set cli screen-length 0")
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32lib\site-packages\netmiko\base_connection.py", line 1031, in disable_paging
output = self.read_until_pattern(pattern=re.escape(command.strip()))
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32lib\site-packages\netmiko\base_connection.py", line 627, in read_until_pattern
return self._read_channel_expect(
args, **kwargs)
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32lib\site-packages\netmiko\base_connection.py", line 560, in _read_channel_expect
raise NetmikoTimeoutException(
netmiko.ssh_exception.NetmikoTimeoutException: Timed-out reading channel, data not available.

All 8 comments

Can you get me the log-output for a failing device?

https://github.com/ktbyers/netmiko/blob/develop/COMMON_ISSUES.md#enable-netmiko-logging-of-all-reads-and-writes-of-the-communications-channel

Thanks for your reply. You can find the log-output attached (i have only replaced the sensitive information - being a production device). It looks like it is failing to send any of the commands from the file for some reason.

testlog.txt

I'm having the exact same issue, but with a Nokia/Alcatel device.

In my case, I'm running three separate commands, the first two execute as expected, but the third does not. It doesn't seem to be related to the length of the returned command output, as I can substitute a different command in that third spot with longer output and get back a response. I'm suspecting maybe it's something to do with the format of the output confusing netmiko.

Here's my relevant code:

connection_detail = {
                "host": txsys_result[key]["ip"],
                "username": username,
                "password": passwd,
                "device_type": "nokia_sros"
}
net_connect = Netmiko(**connection_detail)
net_connect.send_command("environment no more")
router_int_data = net_connect.send_command("show router interface")
router_ospf_data = net_connect.send_command(f'show router ospf interface {txsys_result[key]["port"]}')
router_metric_data = net_connect.send_command(f'show router ospf interface {txsys_result[key]["port"]} detail')
net_connect.disconnect()

I have confirmed from the devices that the correct commands are being received, and as per your suggestion here's the log output(some details have been edited from the command output, but the structure is intact).

Thanks for any assistance you can provide.
netmiko.log

Hi Kirk,

Did you have time to check the log? Any idea what is going on and how to fix it?

@lrmrxhp Can you test this fix here:

https://github.com/ktbyers/netmiko/pull/1736

@Enochsoul Can you open up a separate issue? They look like separate issues.

Hey Kirk, it worked. I imported the modified BaseConnection file and disabled the global_cmd_verify:

session = BaseConnection(host = each_device, username = username, password = password, device_type = 'juniper', auth_timeout = 5.0, global_cmd_verify = False)

It is now working on all my juniper devices.

Thanks for your help with this, I really appreciate it :).

Okay, I merged that PR into Netmiko so it is now in the Netmiko develop branch (and should be included with the next Netmiko release).

Was this page helpful?
0 / 5 - 0 ratings