Python list index out of range - minidom

TStodden

New Member
Quick question, what is the correct solution when you see the error 'builtins.IndexError: list index out of range'?This is in reference to another thread I've got going, but I'd prefer not to derail it.Code:\[code\]from xml.dom import minidomnet_xml = minidom.parse("network_objects.xml")NetworkObjectsTag = net_xml.getElementsByTagName("network_objects")[0]# Pull individual network objectsNetworkObjectTag = NetworkObjectsTag.getElementsByTagName("network_object")for network_object in NetworkObjectTag: name = network_object.getElementsByTagName("Name")[0].firstChild.data class_name = network_object.getElementsByTagName("Class_Name")[0].firstChild.data color = network_object.getElementsByTagName("color")[0].firstChild.data ipElement = network_object.getElementsByTagName("ipaddr")[0] ipaddr = ipElement.firstChild.data maskElement = network_object.getElementsByTagName("netmask")[0] netmask = maskElement.firstChild.data #address_ranges ipaddr_first = network_object.getElementsByTagName("ipaddr_first") ipaddr_last = network_object.getElementsByTagName("ipaddr_last") print(name,class_name,ipaddr,netmask,ipaddr_first,ipaddr_last,color)\[/code\]The error that is generated after printing 6 lines is:\[code\]ipElement = network_object.getElementsByTagName("ipaddr")[0]IndexError: list index out of range\[/code\]
 
Back
Top