我有以下使用netmiko的
def main():
timestamp = datetime.now().strftime("%Y-%m-%d_%H:%M:%S")
print(timestamp)
net_connect = ConnectHandler(device_type='paloalto_panos', ip='nodeip', username='admin', password='password')
net_connect.find_prompt()
net_connect.send_config_set('save config to config' + timestamp + '.xml')
# output = net_connect.send_command('configure')
# print(output)
# output = net_connect.send_command('save config to config' + timestamp + '.xml')
# print(output)
# output = net_connect.send_command('exit')
# print(output)
output = net_connect.send_command('tftp export configuration from config' + timestamp + '.xml' + 'to 10.1.1.1')
print(output)
main()脚本连接良好,但在net_connect.send_config_set命令中“挂起”。
我还尝试发送“配置”命令,然后用相同的结果发送"exit“。然后,我记得在配置模式下,它需要一个不同的提示,所以我使用了"send_config_set“方法。超时后,脚本将返回:
raceback (最近一次调用):文件"",第1行,在文件"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/netmiko/base_connection.py",第921行(“配置到配置”+时间戳+ '.xml')中在send_config_set output += self.exit_config_mode() File self.exit_config_mode第48行中,在exit_config_mode output = self.send_command(exit_config,strip_prompt=False,文件"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/netmiko/paloalto/paloalto_panos_ssh.py",第154行,在send_command中返回超级(PaloAltoPanosSSH,self).send_command(*args,**kwargs)文件"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/netmiko/base_connection.py",行770,(在send_command search_pattern中) OSError:搜索模式从未在send_command_expect中检测到: admin\@PA-200#
发布于 2018-03-09 23:14:13
send_config_set()需要一个命令列表,而不是一个字符串。该命令正在进入配置模式,并将命令字符串中的每个字符作为单独的命令发送。
试着像这样做:
net_connect.send_config_set(['save config to config' + timestamp + '.xml'])
请注意,此答案仅适用于较早版本的Netmiko。当前版本正确地解释了str输入,而不需要列表。
https://stackoverflow.com/questions/42582547
复制相似问题