04-14-2020 09:30 PM
This is my code
from netmiko import ConnectHandler cisco_device = { 'device_type': 'cisco_ios', 'ip': 'R1', 'username': 'u', 'password': 'p' } with open('command.txt') as c: cmd = c.read().splitlines() net_connect = ConnectHandler(**cisco_device) output = net_connect.send_command(cmd) print(output)
command.txt
show clock show version | include IOS
output
user@linux:~$ python script.py Traceback (most recent call last): File "script.py", line 14, in <module> output = net_connect.send_command(cmd) File "/home/user/.local/lib/python3.7/site-packages/netmiko/utilities.py", line 347, in wrapper_decorator return func(self, *args, **kwargs) File "/home/user/.local/lib/python3.7/site-packages/netmiko/base_connection.py", line 1378, in send_command command_string = self.normalize_cmd(command_string) File "/home/user/.local/lib/python3.7/site-packages/netmiko/base_connection.py", line 1532, in normalize_cmd command = command.rstrip() AttributeError: 'list' object has no attribute 'rstrip' user@linux:~$
What should I do to fix this problem?
I tried to change `splitlines` to `split`, but it didn't change anything. Still getting the same error.
Solved! Go to Solution.