Python 属性错误:';非类型';对象没有属性';nodeValue';

Python 属性错误:';非类型';对象没有属性';nodeValue';,python,android-ksoap2,ksoap,Python,Android Ksoap2,Ksoap,我正在使用ksoap在一个android应用程序和包含以下文件的python服务器之间进行通信。我正在尝试检索发布的XML文件中的所有值。但我一直得到,AttributeError:'NoneType'对象没有属性'nodeValue'。当我试图调试错误但仍然失败时,有人能告诉我代码出了什么问题吗 XML文件的一部分(只有MacFilterList和Map节点可以为空): profileData.py(其中,XML\u ProfileDataStore类为: 这意味着某个方法/属性返回了None

我正在使用ksoap在一个android应用程序和包含以下文件的python服务器之间进行通信。我正在尝试检索发布的XML文件中的所有值。但我一直得到,
AttributeError:'NoneType'对象没有属性'nodeValue'
。当我试图调试错误但仍然失败时,有人能告诉我代码出了什么问题吗

XML文件的一部分(只有MacFilterList和Map节点可以为空):

profileData.py(其中,
XML\u ProfileDataStore
类为:


这意味着某个方法/属性返回了
None
,您试图访问它的
nodeValue
属性。 要么您的算法错误,要么您需要在访问属性之前测试
None

很抱歉,我帮不了你更多的忙,我从未使用过这个库。

首先,请发布错误消息好吗?然后,尝试隔离代码中的行,为了进行调试,请在此行之前使用一些脏的
打印节点、node.name
(或类似的内容),以便识别破坏保护的XML节点


然后,您应该能够理解为什么这一行是您没有预见到的情况。

不知何故,现在一切正常。在前面,我删除了XML文件中包含任何空元素的节点,当然,当我发现空元素可能导致错误时,这将正常工作。但是,现在我替换回原始XML文件,并且可以检索数据。下面是我编辑的.py文件中的函数,用于检查XML文件中的空元素

    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

由于各种原因出现非类型错误。问题是没有硬编码的方法来知道是什么“线”导致了错误。。。 我所做的是,稍微处理一下po2prop.py文件,以便引入一个“printline”选项。。。 有两种方法可以做到这一点: A.请求一个命令行参数,该参数将导致“printline”标志为true B粗暴地添加一行以打印该行,然后删除或注释该行(更容易)

(b) 是快速完成此操作的简单方法,因此请转到po2prop.py文件并搜索以下行:

    for line in content.splitlines(True):
        outputstr = self.convertline(line)
        outputlines.append(outputstr)
    return u"".join(outputlines).encode(self.encoding)
并在循环代码中添加这一行:

        sys.stdout.write(outputstr)
因此它变为(在代码中注释,需要时取消注释):

就这么简单。 提示:别忘了:

    import sys

在文件的导入部分

xml文件中的某些元素是空元素,并且。然而,在我实现了一些代码行来检查这种情况之后,错误仍然存在。此外,我还在服务器中创建了一个.py文件来检索数据,而不是使用android客户端应用程序,我可以这样做,但没有使用应用程序。回溯(最近一次调用):文件“C:\Users\Qingyan\Desktop\server\SOAPpy\server.py”,第407行,在dou POST fr=apply(f,ordered_args,named_args)文件中“C:\Users\Qingyan\Desktop\Server\WifiPositionSoapAPI.py”,第123行,在GetAllProfileData result=self.profile.GetAllProfileData()文件“C:\Users\Qingyan\Desktop\Server\ProfileDataStore.py”中,第153行,在GetAllProfileData profiles=profiles+ChildNode.firstChild.nodeValue+”,“AttributeError:'非类型'对象没有属性'nodeValue'
    for line in content.splitlines(True):
        outputstr = self.convertline(line)
        outputlines.append(outputstr)
    return u"".join(outputlines).encode(self.encoding)
        sys.stdout.write(outputstr)
    for line in content.splitlines(True):
        outputstr = self.convertline(line)
        outputlines.append(outputstr)
    #   sys.stdout.write(outputstr)
    return u"".join(outputlines).encode(self.encoding)
    import sys