我正在尝试执行一个代码,该代码从文件中读取输入(IP),然后为每个设备执行show命令。我正在尝试使用rstrip
,以便在连接处理程序之前删除\n
,但出现错误:
a_device = a_device.rstrip()
AttributeError: 'dict' object has no attribute 'rstrip'
from netmiko import ConnectHandler
Device_IP = open(r'C:\ATT_Devices.txt','r')
List1 = {
'device_type': 'cisco_ios',
'host': 'Device_IP',
'username': 'USERNAME',
'password': 'PASSWORD',
}
all_devices = [List1]
for a_device in all_devices:
a_device = a_device.rstrip() # error thrown here
net_connect = ConnectHandler(**a_device)
output = net_connect.send_command("show ip bgp summary")
print(output)
答案 0 :(得分:0)
all_devices = [List1]->不将字典转换为列表。 而是尝试使用all_devices = list(List1)->转换dict。进入列表。
all_devices = list(List1)
for a_device in all_devices:
a_device = a_device.rstrip()
print(a_device)