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.

IOError: Search pattern never detected in send_command_expect

See original GitHub issue

Hi,

I am using netmiko and python to collect CPU information from Cisco IOS based access points. In most instances the script works fine, but on other occasions it fails and I cannot determine why.

python version = 2.7.8 netmiko version = 1.0.0 paramiko version = 2.0.2

Code sample:

            if icmp_response == 0:
                try:
                    device = ConnectHandler(device_type='cisco_ios', ip=APIPAddr, username=Aplogin, password=ApPassword)
                    sleep(0.5)
                    output = (device.send_command('show proc cpu | include LWAPP CLIENT')).encode("utf-8").split()
                    sleep(0.5)
                    device.disconnect()
                    logging.info('CPU usage for %s (%s) @ %s' % (DeviceName, DeviceIP, output[5].strip('%')))
                except NetMikoTimeoutException:
                    logging.info('SSH connection failed to %s (%s)' % (DeviceName, DeviceIP))
                except NetMikoAuthenticationException:
                    logging.info('AP Authentication Failure for %s (%s)' % (DeviceName, DeviceIP))
                except Exception:
                    logging.exception('Exception for %s (%s)' % (DeviceName, DeviceIP))
                    logging.info('Exception ...', output)
            else:
                logging.info('Device not pingable for %s, %s' % (DeviceName, DeviceIP))

Log Message:

Sat, 08 Oct 2016 12:36:01 CPU usage for ap2602 (10.36.14.152) @ ['81', '51008', '1355556', '37', '0.00%', '0.00%', '0.00%', '0', 'LWAPP', 'CLIENT']
Sat, 08 Oct 2016 12:36:01 CPU usage for ap2602 (10.36.14.152) @ 0.00
Sat, 08 Oct 2016 12:36:09 CPU usage for ap2602 (10.36.190.159) @ ['81', '26408', '915727', '28', '0.00%', '0.00%', '0.00%', '0', 'LWAPP', 'CLIENT']
Sat, 08 Oct 2016 12:36:09 CPU usage for ap2602 (10.36.190.159) @ 0.00

Error Message:

Sat, 08 Oct 2016 12:38:00 Exception for ap2602 (10.x.x.x)
Traceback (most recent call last):
  File "/home/user1/CheckCPU.py", line 430, in CPUQuery
    output = (device.send_command('show proc cpu sort | inc LWAPP CLIENT')).encode("utf-8").split()
  File "/home/user1/venv/lib/python2.7/site-packages/netmiko/base_connection.py", line 645, in send_command
    search_pattern))
IOError: Search pattern never detected in send_command_expect: 51

Sat, 08 Oct 2016 12:38:00 *** CPUQuery() Error ***
Traceback (most recent call last):
  File "/home/user1/CheckCPU.py", line 443, in CPUQuery
    logging.info('Exception ...', output)
UnboundLocalError: local variable 'output' referenced before assignment

Manual Test:

[user1@hj1 ~]$ ssh -l admin 10.x.x.x
The authenticity of host '10.x.x.x (10.x.x.x)' can't be established.
RSA key fingerprint is 6b:c5:79:6e:13:f5:00:00:00:00:bb:08:99:5a:0d:b4.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.x.x.x' (RSA) to the list of known hosts.
Password: 
ap2602>show proc cpu | include LWAPP CLIENT
  81       35028      870017         40  0.00%  0.00%  0.00%   0 LWAPP CLIENT     
ap2602>quit
Connection to 10.x.x.x closed.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ktbyerscommented, Oct 11, 2016

@zeepi222 Okay, wrong format. It is an attribute (not a method) so no parenthesis.

print(device.base_prompt)

Try the following and let me know if it works:

time.sleep(3)
device.clear_buffer()
output = (device.send_command('show processes cpu | include CPU', expect_string='ap2602>')).encode("utf-8").split()

The send_command_expect() method tries to determine the routers prompt and use this as a trailing pattern for determining command completion. This looks like it is failing (possibly due to the router being slow).

This will only work for that one particular device, but I want to see if it fixes your problem.

0reactions
carrascodccommented, Aug 16, 2019

I wrote a script that worked with Cisco NXOS and IOS, and then I tried to apply it to the F5 LTM and hit this error. The solution mentioned by zeepi222 fixed this problem. Thank you !!!

net_connect = ConnectHandler(**Node) time.sleep(2) <<< Resolved this error message print(net_connect.find_prompt()) print(net_connect.send_command(‘modify security firewall address-list EXT-Test addresses add {1.1.1.1}’) print(net_connect.send_command(‘modify security firewall address-list EXT-Test addresses add {4.4.4.4}’)

Read more comments on GitHub >

github_iconTop Results From Across the Web

IOError: Search pattern never detected in ... - GitHub
Hi, I apologize in advance if I could've found the answer to this ... IOError: Search pattern never detected in send_command_expect #821.
Read more >
Python Netmiko OSError: Search pattern never detected in ...
in the command with which the state dump is created, I have increased the "send_command" delay factor to 5.
Read more >
Netmiko TFTP Issue when using scraped variables - Reddit
OSError: Search pattern never detected in send_command_expect: GBA\-00\-SWA\-Build\-01\# ... raise IOError(. OSError: Search pattern never ...
Read more >
Netmiko and what constitutes done
In other words, Netmiko will attempt to find the existing prompt ... Search pattern never detected in send_command_expect: pynet\-rtr1\#.
Read more >
Netmiko OSError: Search pattern never .. - W3coded.com
Netmiko OSError: Search pattern never detected in send_command_expect: Destination python,netmiko,send_command_expect,detected,pattern,search,oserror.
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