Sunday, May 3, 2020

Cant run Netmiko script in Unbuntu

root@Ubuntu-2:~# python3 pythonv1 Traceback (most recent call last): File "pythonv1", line 1, in <module> import netmiko File "/usr/local/lib/python3.5/dist-packages/netmiko/__init__.py", line 7, in <module> from netmiko.ssh_dispatcher import ConnectHandler File "/usr/local/lib/python3.5/dist-packages/netmiko/ssh_dispatcher.py", line 2, in <module> from netmiko.a10 import A10SSH File "/usr/local/lib/python3.5/dist-packages/netmiko/a10/__init__.py", line 1, in <module> from netmiko.a10.a10_ssh import A10SSH File "/usr/local/lib/python3.5/dist-packages/netmiko/a10/a10_ssh.py", line 3, in <module> from netmiko.cisco_base_connection import CiscoSSHConnection File "/usr/local/lib/python3.5/dist-packages/netmiko/cisco_base_connection.py", line 143 msg = f"Login failed: {self.host}" 

Hi, i'm trying to run a python script i've wrote for writing commands to a Cisco switch using Netmiko but i'm getting these errors i'm assuming to do with importing the module but i'm not sure why...
Here is the script......

import netmiko import getpass print("Please enter the password") password = getpass.getpass() cisco_switch = { 'device_type': 'cisco_ios', 'host': '10.1.1.1', 'username': 'admin', 'password': password } net_connect = netmiko.ConnectHandler(**cisco_switch) net_connect.find_prompt() commands = ["conf t", "int loop 0", "ip add 1.1.1.1 255.255.255.0", "\n"] net_connect.send_config_set(commands) output = net_connect.send_command("sho ip int bri") #####print(f"\n------------{cisco_switch['device_type']}----------") print(output) print("----------------------------------------------------") net_connect.save_config() net_connect.disconnect() 

Just as an extra snippet, the line where i've put #####, i was getting a syntax error there to so i commented it out but i couldn't see why it was throwing up an error with that syntax.



No comments:

Post a Comment