1
votes

I have the following using 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()

the script connects fine, but "hangs" during the net_connect.send_config_set command.

I also tried sending "configure" the the command and then "exit" with the same result. Then I remembered that in config mode it's expecting a different prompt so I used the "send_config_set" method. After a timeout, the script comes back with:

raceback (most recent call last): File "", line 1, in net_connect.send_config_set('save config to config' + timestamp + '.xml') File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/netmiko/base_connection.py", line 921, in send_config_set output += self.exit_config_mode() File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/netmiko/paloalto/paloalto_panos_ssh.py", line 48, in exit_config_mode output = self.send_command(exit_config, strip_prompt=False, strip_command=False) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/netmiko/paloalto/paloalto_panos_ssh.py", line 154, in send_command return super(PaloAltoPanosSSH, self).send_command(*args, **kwargs) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/netmiko/base_connection.py", line 770, in send_command search_pattern)) OSError: Search pattern never detected in send_command_expect: admin\@PA-200#

1

1 Answers

0
votes

send_config_set() is expecting a Python list of commands, not a single string. The command is entering configuration mode, and sending each character in your command string as a separate command.

Try it like this instead:

net_connect.send_config_set(['save config to config' + timestamp + '.xml'])

Note that this answer only applies to older versions of Netmiko. Current versions correctly interpret a str input rather than requiring a list.