IOError: Search pattern never detected in send_command_expect
See original GitHub issueHi,
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:
- Created 7 years ago
- Comments:13 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@zeepi222 Okay, wrong format. It is an attribute (not a method) so no parenthesis.
Try the following and let me know if it works:
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.
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}’)