AttributeError: 'NoneType' object has no attribute 'nodeValue'

user918197 picture user918197 · Sep 4, 2011 · Viewed 16.1k times · Source

I am using ksoap to communicate between an android app and the python server containing the following files posted. I am trying to retrieve all the values in the XML file posted. But i keep getting, AttributeError: 'NoneType' object has no attribute 'nodeValue'. Can anyone tell me what's wrong with the code as I tried to debug the error but still failed to do so.

Portion of the XML file (only MacFilterList and Map node can be empty):

<ProfileList>
<Profile>
    <ProfileName>Lab1</ProfileName>
    <Owner>admin</Owner>
    <Map>Lab</Map>
    <Visible>True</Visible>
    <MacFilterList>
        <string>00:14:BF:9F:5D:3A</string>
        <string>00:14:BF:9F:5D:52</string>
        <string>00:14:BF:9F:5D:37</string>
        <string>00:14:BF:9F:5D:43</string>
    </MacFilterList>
</Profile>
    .
    .
</ProfileList>

soapAPI.py (PROFILE_XML refers to the filename of the xml file.):

def __init__(self):  
    self.profileFile = Config.PROFILE_XML
    self.profile = XML_ProfileDataStore()
    self.profile.LoadXMLFile(self.profileFile) 
               .
               .
def GetAllProfileData(self):
    self.profileFile = Config.PROFILE_XML
    self.profile.LoadXMLFile(self.profileFile) 
    result = self.profile.GetAllProfileData()
    return result 

profileData.py (where the class, XML_ProfileDataStore is):

def GetAllProfileData(self):

    #Get a node list containing nodes with name Location
    ProfileList = self.XMLdoc.getElementsByTagName('Profile')
    NumArgCheck = 0
    profiles=""

    #For each location node in list
    for profileNode in ProfileList:
        #For each child nodes in Location node, compare the XY coordinates
        for ChildNode in profileNode.childNodes:
            #If child node has profile name profile_name
            if (cmp(ChildNode.nodeName, 'ProfileName') == 0):
                NumArgCheck += 1
                profiles = profiles + ChildNode.firstChild.data + ","
                ChildNode = ChildNode.nextSibling
                profiles = profiles + ChildNode.firstChild.nodeValue + ","
                ChildNode = ChildNode.nextSibling
                profiles = profiles + ChildNode.firstChild.nodeValue + ","
                ChildNode = ChildNode.nextSibling
                profiles = profiles + ChildNode.firstChild.nodeValue
                ChildNode = ChildNode.nextSibling

                for child in ChildNode.childNodes:
                   profiles = profiles + "," + child.firstChild.nodeValue
                profiles = profiles+";"

    return profiles

Answer

Bastien L&#233;onard picture Bastien Léonard · Sep 4, 2011

It means that some method/attribute returned None, and you tried to access its nodeValue attribute. Either your algorithm is wrong, or you need to test for None before accessing the attribute. Sorry but I can't help you more than that, I have never used this library.