netmiko 脚本
from netmiko import ConnectHandler
iosv_l2 = {
'device_type': 'cisco_ios',
'ip': '192.168.122.2',
'username': 'test',
'password': '123',
}
net_connect = ConnectHandler(**iosv_l2)
output = net_connect.send_command('show ip int brief')
print (output)
config_commands = ['int loop 0', 'ip address 1.1.1.1 255.255.255.0']
output = net_connect.send_config_set(config_commands)
print (output)
for n in range (2,21):
print ("Creating VLAN " + str(n))
config_commands = ['vlan ' + str(n), 'name Python_VLAN ' + str(n)]
output = net_connect.send_config_set(config_commands)
print (output)
我最终遇到了这个错误
接口 IP 地址好吗?方法状态协议 GigabitEthernet0/0 未分配 YES 未设置 GigabitEthernet0/1 unassigned YES unset down down vlan1 192.168.122.2 YES 手动 up up 回溯(最近一次通话最后): 文件“/usr/local/lib/python3.8/dist-packages/paramiko/channel.py”,第 699 行,在 recv out = self.in_buffer.read(nbytes, self.timeout) 文件“/usr/local/lib/python3.8/dist-packages/paramiko/buffered_pipe.py”,第 164 行,读取 提高 PipeTimeout() paramiko.buffered_pipe.PipeTimeout 在处理上述异常的过程中,又出现了一个异常: 回溯(最近一次通话最后): _read_channel_expect 中的文件“/usr/local/lib/python3.8/dist-packages/netmiko/base_connection.py”,第 534 行 new_data = self.remote_conn.recv(MAX_BUFFER) 文件“/usr/local/lib/python3.8/dist-packages/paramiko/channel.py”,第 701 行,在 recv 提高 socket.timeout() 套接字超时 在处理上述异常的过程中,又出现了一个异常: 回溯(最近一次通话最后): 文件“ssh.py”,第 15 行,在 输出 = net_connect.send_config_set(config_commands) 文件“/usr/local/lib/python3.8/dist-packages/netmiko/base_connection.py”,第 1607 行,在 send_config_set 输出 = self.config_mode(*cfg_mode_args) 文件“/usr/local/lib/python3.8/dist-packages/netmiko/cisco_base_connection.py”,第 49 行,在 config_mode 返回超级(CiscoBaseConnection,self).config_mode( config_mode 中的文件“/usr/local/lib/python3.8/dist-packages/netmiko/base_connection.py”,第 1514 行 如果不是 self.check_config_mode(): 文件“/usr/local/lib/python3.8/dist-packages/netmiko/cisco/cisco_ios.py”,第 31 行,在 check_config_mode return super(CiscoIosBase, self).check_config_mode( 文件“/usr/local/lib/python3.8/dist-packages/netmiko/cisco_base_connection.py”,第 37 行,在 check_config_mode 返回 super(CiscoBaseConnection, self).check_config_mode( 文件“/usr/local/lib/python3.8/dist-packages/netmiko/base_connection.py”,第 1501 行,在 check_config_mode 输出 = self.read_until_pattern(pattern=pattern) 文件“/usr/local/lib/python3.8/dist-packages/netmiko/base_connection.py”,第 609 行,在 read_until_pattern 返回 self._read_channel_expect(*args, **kwargs) _read_channel_expect 中的文件“/usr/local/lib/python3.8/dist-packages/netmiko/base_connection.py”,第 542 行 引发 NetMikoTimeoutException( netmiko.ssh_exception.NetMikoTimeoutException:读取通道超时,数据不可用。
我如何解决这个问题...