I just created a python code using netmiko for cisco switches but i receive errors when i run it... i want to use the commands to go to enable mode of switch but it doesn't work...
from netmiko import ConnectHandler
cisco_Router = {
"device_type": "cisco_ios_telnet",
"host": "123.123.1.2",
"username": "username",
"password": "password"}
with ConnectHandler(**cisco_Router) as net_connect:
net_connect.enable()
result = net_connect.send_command('sh run')
net_connect.disconnect()
print(result)
This is the error:
Traceback (most recent call last):
File "E:\netmiko\sw_enable.py", line 12, in <module>
net_connect.enable()
File "C:\Users\Siavash\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\netmiko\cisco_base_connection.py", line 26, in enable
return super().enable(
File "C:\Users\Siavash\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\netmiko\base_connection.py", line 2042, in enable
output += self.read_until_prompt()
File "C:\Users\Siavash\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\netmiko\base_connection.py", line 837, in read_until_prompt
return self.read_until_pattern(
File "C:\Users\Siavash\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\netmiko\base_connection.py", line 746, in read_until_pattern
raise ReadTimeout(msg)
netmiko.exceptions.ReadTimeout:
Pattern not detected: 'switch' 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.
One issue could be that the netmiko device_type doesn't support the OS running on the switch. If connecting via SSH isn't an option, then there are 4 telnet device_type available, namely cisco_ios_telnet, cisco_xr_telnet, cisco_s200_telnet, and cisco_s300_telnet. Try changing your device_type to one of those to see if one of those works. Otherwise, configure the switch to use SSH and try one of the many device_types that best matches your switch's OS.