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.

ansi escape code in output causing send_command to not work

See original GitHub issue
def sshConnection():
    file = open('sessionLog.txt', 'w+')
    while True:
        try:
            panIP = input("Panorama IP: ")
            fwIP = input("Firewall IP: ")
            username = input("Username: ")
            password = getpass()
            panosConn = ConnectHandler(device_type = "paloalto_panos", host = panIP, username = username, password = password, session_log = 'sessionLog.txt')
            break
        except (NetMikoAuthenticationException, NetMikoTimeoutException):
            print("Authentication Failed")
            pass
    panosConn.send_command('ssh host '+username+'@'+fwIP+'',  expect_string = r'Password')
    panosConn.send_command(''+password+'', expect_string = r'>')
    panosConn.find_prompt()
    panosConn.send_command('set cli pager off')

Traceback (most recent call last): File “C:\pyscripts\netmiko3\lib\site-packages\paramiko\channel.py”, line 699, in recv out = self.in_buffer.read(nbytes, self.timeout) File “C:\pyscripts\netmiko3\lib\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:\pyscripts\netmiko3\lib\site-packages\netmiko\base_connection.py”, line 541, in _read_channel_expect new_data = self.remote_conn.recv(MAX_BUFFER) File “C:\pyscripts\netmiko3\lib\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 “.\pacPeople.py”, line 85, in <module> main() File “.\pacPeople.py”, line 81, in main panosConn = sshConnection() File “.\pacPeople.py”, line 45, in sshConnection panosConn.send_command(‘ssh host ‘+username+’@’+fwIP+‘’, expect_string = r’Password’) File “C:\pyscripts\netmiko3\lib\site-packages\netmiko\paloalto\paloalto_panos.py”, line 160, in send_command return super().send_command(*args, **kwargs) File “C:\pyscripts\netmiko3\lib\site-packages\netmiko\base_connection.py”, line 1366, in send_command new_data = self.read_until_pattern(pattern=re.escape(cmd)) File “C:\pyscripts\netmiko3\lib\site-packages\netmiko\base_connection.py”, line 618, in read_until_pattern return self._read_channel_expect(*args, **kwargs) File “C:\pyscripts\netmiko3\lib\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.

Using expect_string for ssh proxy through another device no longer working in ver 3.0.0 , was previously working in 2.4.2

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
ktbyerscommented, Jan 28, 2020

Netmiko 2.4.2 is different than Netmiko 3.0.0 here (Netmiko 3.0.0 is trying to verify the command echo whereas Netmiko 2.4.2 didn’t)…so that part is expected.

Verifying the command echo fixes a lot of other Netmiko problems.

1reaction
wfleishercommented, Jan 28, 2020

No only replaced the last octet. The space is present in the log when I run the script in 2.4.2 as well

Read more comments on GitHub >

github_iconTop Results From Across the Web

Huawei has ANSI escape codes in the output that need ...
Okay, then we need to work on that the 'send_command' not working on Huawei VRP8 (which issue was that)?. Any fix/research needs to...
Read more >
ANSI escape code not working properly [C++] - Stack Overflow
I am getting proper colored output in vs code integrated terminal. enter image description here. But when I am running the program in...
Read more >
Build your own Command Line with ANSI escape codes
These are the Ansi escape codes that programs like Bash use to let you move your cursor left and right across your input...
Read more >
Where do my ANSI escape codes go when I pipe to another ...
The simplest way to capture color output from a program like that is to tell it to write color even though it's not...
Read more >
ANSI escape code - Wikipedia
ANSI escape sequences are a standard for in-band signaling to control cursor location, color, font styling, and other options on video text terminals...
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