Question

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
Was it helpful?

Solution

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.

OTHER TIPS

NoneType error appears for various reasons. The problem is that there is no hardcoded way to know what "line" causes the error... What I did, was play a little with the po2prop.py file, in order to introduce a "printline" option... There are two ways to do that: a. Request a command line argument which will cause a "printline" flag to be true b. Brutally add a line to print the line and then remove it or comment it (easier)

(b) is the easy way to do it fast, so go to your po2prop.py file and search for lines:

    for line in content.splitlines(True):
        outputstr = self.convertline(line)
        outputlines.append(outputstr)
    return u"".join(outputlines).encode(self.encoding)

and add this line in the loop code:

        sys.stdout.write(outputstr)

So it becomes (it is commented in the code, uncomment it when needed):

    for line in content.splitlines(True):
        outputstr = self.convertline(line)
        outputlines.append(outputstr)
    #   sys.stdout.write(outputstr)
    return u"".join(outputlines).encode(self.encoding)

As simple as that. HINT: DON'T FORGET TO:

    import sys

at the import section of the file

First, could you please publish the error message? Then, try to isolate the line in your code, and for debugging, use some dirty print node, node.name (or something similar) before this line, in order to identify the XML node that is breaking your protection.

You should then be able to understand why this line is a case you did not foresee.

Somehow everything is working fine now. Previously, i remove the nodes in the XML file which contain any empty elements and of course that would be working fine as i find out that the empty element might be causing the error. However, now i replace back the original XML file and data can be retrieved. Here is the function from the .py file which i had edited to check for empty element within the XML file.

    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
                #If element is empty
                if ChildNode.firstChild is not None:
                    profiles = profiles + ChildNode.firstChild.nodeValue + ","
                else:
                    profiles = profiles + "EMPTY,"

                ChildNode = ChildNode.nextSibling

                if ChildNode.firstChild is not None:
                    profiles = profiles + ChildNode.firstChild.nodeValue + ","
                else:
                    profiles = profiles + "EMPTY,"

                ChildNode = ChildNode.nextSibling

                if ChildNode.firstChild is not None:
                    profiles = profiles + ChildNode.firstChild.nodeValue + ","
                else:
                    profiles = profiles + "EMPTY,"

                ChildNode = ChildNode.nextSibling

                if ChildNode.firstChild is not None:
                    profiles = profiles + ChildNode.firstChild.nodeValue
                else:
                    profiles = profiles + "EMPTY"

                ChildNode = ChildNode.nextSibling

                if ChildNode.firstChild is not None:
                    for child in ChildNode.childNodes:
                        profiles = profiles + "," + child.firstChild.nodeValue
                else:
                    profiles = profiles + ",EMPTY"

        profiles = profiles+";"

    return profiles
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top