question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Linux-driver terminal width is not being set by Netmiko

See original GitHub issue

Hi,

Using Netmiko version 3.0.0 I am trying to connect to a Linux box & then sending a grep command (grep -w {ip}/32 *.set | grep book | grep -v 1b | grep -v 2b) , however, it fails with the below error.

If I remove the pipes ( | ) from the command it works just fine.

Error is pipe related-

raise PipeTimeout() paramiko.buffered_pipe.PipeTimeout

I shouldn’t say its a netmiko error rather some piece of code in the /paramiko/channel.py is complaining. However, if I downgrade the Netmiko to version 2.4.2, this error is never thrown & code finishes without any issues. Paramiko version that I am using is 2.7.1 .

Code:

from netmiko import ConnectHandler
secmt = {'device_type': 'linux','ip': 'secmt03','username': username,'password': '***********' }
secmt_connect = ConnectHandler(**secmt)
grep_op = secmt_connect.send_command_expect(
    f'grep -w {ip}/32 *.set | grep book | grep -v 1b | grep -v 2b', expect_string = 'secmt junos-firewall'
) 
print(grep_op)

Error:

Traceback (most recent call last): File “/home/satnau/.local/lib/python3.6/site-packages/paramiko/channel.py”, line 699, in recv out = self.in_buffer.read(nbytes, self.timeout) File “/home/satnau/.local/lib/python3.6/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 “/home/satnau/.local/lib/python3.6/site-packages/netmiko/base_connection.py”, line 541, in _read_channel_expect new_data = self.remote_conn.recv(MAX_BUFFER) File “/home/satnau/.local/lib/python3.6/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 “DNS_PING_FIREWALL_TESTING_V2.0.py”, line 243, in <module> junos_fw_info = secmt_connect.send_command_expect(f’grep -w {ip}/32 *.set | grep book | grep -v 1b | grep -v 2b’, expect_string = ‘secmt junos-firewall’) File “/home/satnau/.local/lib/python3.6/site-packages/netmiko/base_connection.py”, line 1447, in send_command_expect return self.send_command(*args, **kwargs) File “/home/satnau/.local/lib/python3.6/site-packages/netmiko/base_connection.py”, line 1366, in send_command new_data = self.read_until_pattern(pattern=re.escape(cmd)) File “/home/satnau/.local/lib/python3.6/site-packages/netmiko/base_connection.py”, line 618, in read_until_pattern return self._read_channel_expect(*args, **kwargs) File “/home/satnau/.local/lib/python3.6/site-packages/netmiko/base_connection.py”, line 552, in _read_channel_expect “Timed-out reading channel, data not available.” netmiko.ssh_exception.NetmikoTimeoutException: Timed-out reading channel, data not available.

Thanks, Satish

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:17 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
ktbyerscommented, Feb 20, 2020

@satnau Does changing your column width on the Netmiko-linux SSH session prior to executing your long command fix your issue?

net_connect.send_command('stty cols 1023')

Kirk

0reactions
satnaucommented, Mar 2, 2020

@ktbyers - Yes the solution that you provided worked like a charm! Thanks a ton…

Read more comments on GitHub >

github_iconTop Results From Across the Web

netmiko API documentation - GitHub Pages
CLI terminals try to automatically adjust the line based on the width of the terminal. This causes the output to get distorted when...
Read more >
Getting console width Python 2 Linux - Stack Overflow
@Jan I created venv and I use Python 2.7.15 there. python --version says Python 2.7.15 And I did not try to reinstall modules...
Read more >
netmiko - PyPI
Multi-vendor library to simplify legacy CLI connections to network devices.
Read more >
Module netmiko - Python for network engineers - Read the Docs
Netmiko is a module that makes it easier to use paramiko for network ... terminal length command is not passed because netmiko executes...
Read more >
Could not establish an ssh connection on router using NETMIKO
I established the first connexion to R1 , and I used Netmiko to ssh to the router ... DEBUG:netmiko:write_channel: b'terminal width 511\n'
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found