We are using opengear to connect Cisco devices via the console port remotely, I need to put some configuration through the console port. I refer to this link Netmiko - Enter configuration terminal mode and wrote below codes. When I run the code, it throw the error, but if I debug the code using pycharm, it works. From the device console, I can see if I run the code under debug mode, the device is activated and get into enable mode, but if I run the code directly, there is no response from the device.
Is there anything that I have missed?
from netmiko import ConnectHandler, redispatch
device = {
"device_type": "terminal_server",
"ip": "****",
"username": "****",
"password": "****",
"session_log": 'netmiko_session.log',
"port": '22'
}
net_connect = ConnectHandler(**device)
net_connect.write_channel("\r")
net_connect.enable()
net_connect.send_command_timing("enable")
redispatch(net_connect, device_type="cisco_xe")
output = net_connect.send_command("show version")
print(output)
net_connect.disconnect()
Here is error
Traceback (most recent call last):
File "C:\Users\user\venv\console_conn.py", line 24, in <module>
redispatch(net_connect, device_type="cisco_xe")
File "C:\Users\user\venv\lib\site-packages\netmiko\ssh_dispatcher.py", line 487, in redispatch
obj._try_session_preparation()
File "C:\Users\user\venv\lib\site-packages\netmiko\base_connection.py", line 963, in _try_session_preparation
self.session_preparation()
File "C:\Users\user\venv\lib\site-packages\netmiko\cisco\cisco_ios.py", line 19, in session_preparation
self.set_terminal_width(command=cmd, pattern=cmd)
File "C:\Users\user\lib\site-packages\netmiko\base_connection.py", line 1322, in set_terminal_width
output = self.read_until_pattern(pattern=pattern)
File "C:\Users\user\venv\lib\site-packages\netmiko\base_connection.py", line 721, in read_until_pattern
raise ReadTimeout(msg)
netmiko.exceptions.ReadTimeout:
Pattern not detected: 'terminal width 511' in output.
Things you might try to fix this:
1. Adjust the regex pattern to better identify the terminating string. Note, in
many situations the pattern is automatically based on the network device's prompt.
2. Increase the read_timeout to a larger value.
You can also look at the Netmiko session_log or debug log for more information.
Had simmilar issue with Arista EOS using netmiko.
In log found
After this set
fast_cliandauto_connectto False and addedestablish_connectionmethod to my ssh connection.Hope, this will help if it`s still actual