gpt4 book ai didi

python - 属性错误 : 'NoneType' object has no attribute 'nodeValue'

转载 作者:行者123 更新时间:2023-11-28 16:51:11 27 4
gpt4 key购买 nike

我正在使用 ksoap 在 android 应用程序和包含以下已发布文件的 python 服务器之间进行通信。我正在尝试检索发布的 XML 文件中的所有值。但我不断收到,AttributeError: 'NoneType' object has no attribute 'nodeValue'。谁能告诉我代码有什么问题,因为我尝试调试错误但仍然失败。

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

<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 指的是 xml 文件的文件名。):

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(类 XML_ProfileDataStore 所在的位置):

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

最佳答案

这意味着某些方法/属性返回了None,而您试图访问它的nodeValue 属性。您的算法有误,或者您需要在访问属性之前测试 None。抱歉,我帮不了你更多,我从来没有用过这个库。

关于python - 属性错误 : 'NoneType' object has no attribute 'nodeValue' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7300225/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com