<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Python Loop issue driving me crazy in Communities of Interest</title>
    <link>https://community.cisco.com/t5/communities-of-interest/python-loop-issue-driving-me-crazy/m-p/4171789#M161</link>
    <description>&lt;P&gt;So i have a python script that applies configs to devices and that part works no problem. The problem is when it hits an exception the script dies. I have looked at a bunch of python resources and I just can't figure it out. Any help would be awesome!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;##imports python modules needed to work&lt;BR /&gt;from netmiko import ConnectHandler&lt;BR /&gt;import time, sys, getpass, paramiko&lt;BR /&gt;from netmiko.ssh_exception import NetMikoTimeoutException&lt;BR /&gt;from netmiko.ssh_exception import NetMikoAuthenticationException&lt;/P&gt;&lt;P&gt;##selects the correct Netmiko class based upon the device_type.&lt;BR /&gt;## I then define a network device dictionary consisting of a device_type, ip, username, and password.&lt;BR /&gt;user = ""&lt;BR /&gt;pword = ""&lt;/P&gt;&lt;P&gt;device = {&lt;BR /&gt;'device_type': 'cisco_ios',&lt;BR /&gt;#'ip': '192.168.43.10',&lt;BR /&gt;'username': user,&lt;BR /&gt;'password': pword,&lt;BR /&gt;#'secret':'password'&lt;BR /&gt;}&lt;BR /&gt;ipfile=open("iplist.txt") #This file contains a list of switch ip addresses.&lt;BR /&gt;#print ("Please doublecheck your configuration in the config file. Please stop and figure out what you're about to do...")&lt;BR /&gt;configfile=open("configfile.txt") #opening the config file with the changes you want to push&lt;BR /&gt;configset=configfile.read() ##reads the config file&lt;BR /&gt;configfile.close() #closes the config file&lt;/P&gt;&lt;P&gt;for line in ipfile:&lt;BR /&gt;device['ip']=line.strip()&lt;BR /&gt;print("Connecting to Device " + line)&lt;BR /&gt;net_connect = ConnectHandler(**device)&lt;BR /&gt;time.sleep(2)&lt;BR /&gt;print ("Applying Configuration to Device " + line)&lt;BR /&gt;output = net_connect.send_config_set(configset)&lt;BR /&gt;print(output)&lt;/P&gt;</description>
    <pubDate>Thu, 22 Oct 2020 13:04:13 GMT</pubDate>
    <dc:creator>wrobbin</dc:creator>
    <dc:date>2020-10-22T13:04:13Z</dc:date>
    <item>
      <title>Python Loop issue driving me crazy</title>
      <link>https://community.cisco.com/t5/communities-of-interest/python-loop-issue-driving-me-crazy/m-p/4171789#M161</link>
      <description>&lt;P&gt;So i have a python script that applies configs to devices and that part works no problem. The problem is when it hits an exception the script dies. I have looked at a bunch of python resources and I just can't figure it out. Any help would be awesome!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;##imports python modules needed to work&lt;BR /&gt;from netmiko import ConnectHandler&lt;BR /&gt;import time, sys, getpass, paramiko&lt;BR /&gt;from netmiko.ssh_exception import NetMikoTimeoutException&lt;BR /&gt;from netmiko.ssh_exception import NetMikoAuthenticationException&lt;/P&gt;&lt;P&gt;##selects the correct Netmiko class based upon the device_type.&lt;BR /&gt;## I then define a network device dictionary consisting of a device_type, ip, username, and password.&lt;BR /&gt;user = ""&lt;BR /&gt;pword = ""&lt;/P&gt;&lt;P&gt;device = {&lt;BR /&gt;'device_type': 'cisco_ios',&lt;BR /&gt;#'ip': '192.168.43.10',&lt;BR /&gt;'username': user,&lt;BR /&gt;'password': pword,&lt;BR /&gt;#'secret':'password'&lt;BR /&gt;}&lt;BR /&gt;ipfile=open("iplist.txt") #This file contains a list of switch ip addresses.&lt;BR /&gt;#print ("Please doublecheck your configuration in the config file. Please stop and figure out what you're about to do...")&lt;BR /&gt;configfile=open("configfile.txt") #opening the config file with the changes you want to push&lt;BR /&gt;configset=configfile.read() ##reads the config file&lt;BR /&gt;configfile.close() #closes the config file&lt;/P&gt;&lt;P&gt;for line in ipfile:&lt;BR /&gt;device['ip']=line.strip()&lt;BR /&gt;print("Connecting to Device " + line)&lt;BR /&gt;net_connect = ConnectHandler(**device)&lt;BR /&gt;time.sleep(2)&lt;BR /&gt;print ("Applying Configuration to Device " + line)&lt;BR /&gt;output = net_connect.send_config_set(configset)&lt;BR /&gt;print(output)&lt;/P&gt;</description>
      <pubDate>Thu, 22 Oct 2020 13:04:13 GMT</pubDate>
      <guid>https://community.cisco.com/t5/communities-of-interest/python-loop-issue-driving-me-crazy/m-p/4171789#M161</guid>
      <dc:creator>wrobbin</dc:creator>
      <dc:date>2020-10-22T13:04:13Z</dc:date>
    </item>
    <item>
      <title>Re: Python Loop issue driving me crazy</title>
      <link>https://community.cisco.com/t5/communities-of-interest/python-loop-issue-driving-me-crazy/m-p/4171835#M162</link>
      <description>&lt;P&gt;Netmiko will send the commands that you specify down the SSH channel. You will need to look at the output of what comes back to see what happened. In your above case, it should report you back as % invalid command from the remote device (if is the invalid config you are looking for?) Netmiko doesn't sanity check the validity of your configuration commands, nor the response returned by the device.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Typically I would use the&amp;nbsp;&lt;/SPAN&gt;&lt;CODE&gt;try&lt;/CODE&gt;&lt;SPAN&gt;&amp;nbsp;and&amp;nbsp;&lt;/SPAN&gt;&lt;CODE&gt;except&lt;/CODE&gt;&lt;SPAN&gt;&amp;nbsp;block in Python, this is used to catch and handle exceptions. For example, Python executes code following the&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;statement as a “normal” part of the program. The code that follows the&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;statement is the program’s response to any exceptions in the preceding try&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;clause. For example, you use this if the device was unreachable.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Hope this helps.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Oct 2020 13:54:08 GMT</pubDate>
      <guid>https://community.cisco.com/t5/communities-of-interest/python-loop-issue-driving-me-crazy/m-p/4171835#M162</guid>
      <dc:creator>bigevilbeard</dc:creator>
      <dc:date>2020-10-22T13:54:08Z</dc:date>
    </item>
    <item>
      <title>Re: Python Loop issue driving me crazy</title>
      <link>https://community.cisco.com/t5/communities-of-interest/python-loop-issue-driving-me-crazy/m-p/4171988#M163</link>
      <description>&lt;P&gt;thank you i will give that a try&lt;/P&gt;</description>
      <pubDate>Thu, 22 Oct 2020 17:27:14 GMT</pubDate>
      <guid>https://community.cisco.com/t5/communities-of-interest/python-loop-issue-driving-me-crazy/m-p/4171988#M163</guid>
      <dc:creator>wrobbin</dc:creator>
      <dc:date>2020-10-22T17:27:14Z</dc:date>
    </item>
  </channel>
</rss>

