2011-09-04 9 views
2

ksoap을 사용하여 Android 앱과 다음 파일이 포함 된 Python 서버간에 통신합니다. 게시 된 XML 파일의 모든 값을 검색하려고합니다. 하지만 계속, AttributeError: 'NoneType' object has no attribute 'nodeValue'. 누구든지 오류를 디버깅하려했지만 여전히 그렇게하지 못했을 때 코드의 문제점을 알 수 있습니까? XML 파일의AttributeError : 'NoneType'객체에 'nodeValue'속성이 없습니다.

부분 (만 MacFilterList 및지도 노드 비어있을 수 있습니다) :

<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 

답변

1

일부 메소드/속성이 None을 반환했으며 해당 nodeValue 속성에 액세스하려고했습니다. 알고리즘에 문제가 있거나 알고리즘에 액세스하기 전에 None을 테스트해야합니다. 미안하지만 나는 그 이상을 도울 수 없다. 나는이 라이브러리를 사용한 적이 없다.

+0

XML 파일의 요소 중 일부를 가져 오기 섹션에서

import sys 

, 그리고 빈 요소이다. 그러나 이러한 경우를 확인하기 위해 코딩을 구현 한 후에도 오류는 여전히 남아 있습니다. 또한 서버에서 .py 파일을 만들어 안드로이드 클라이언트 응용 프로그램 대신 데이터를 검색하는 대신 응용 프로그램이 아닌 안드로이드 클라이언트 응용 프로그램을 사용했습니다. – user918197

0

먼저 오류 메시지를 게시 할 수 있습니까? 그런 다음 코드에서 줄을 분리하고 디버깅을 위해이 줄 앞에 더러운 print node, node.name (또는 비슷한 내용)을 사용하여 보호 기능을 손상시키는 XML 노드를 식별하십시오.

그러면 왜이 줄이 예기치 않은 경우인지 이해할 수 있습니다.

+0

안녕하세요, 질문에 대한 오류 메시지를 추가했습니다. – user918197

0

이제 모든 것이 제대로 작동합니다. 이전에는 XML 파일에서 빈 요소를 포함하는 노드를 제거했으며 물론 빈 요소가 오류를 일으킬 수 있음을 알았 기 때문에 정상적으로 작동합니다. 그러나 이제 원본 XML 파일을 다시 바꿀 수 있으며 데이터를 검색 할 수 있습니다. 다음은 XML 파일 내의 빈 요소를 검사하기 위해 편집했던 .py 파일의 함수입니다.

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 
+0

역 추적 (마지막으로 가장 최근 통화) : 파일 : D 에서 "C \ 사용자 \ Qingyan \ 바탕 화면 \ 서버 \ SOAPpy \ Server.py", 라인 (407), o_POST FR = 적용 (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, i n GetAllProfileData profiles = profiles + ChildNode.firstChild.nodeValue +", " AttributeError : 'NoneType'개체에 'nodeValue'속성이 없습니다. – user918197

1

없음 유형 오류는 여러 가지 이유로 나타납니다. 문제는 어떤 "줄"이 오류를 일으키는 지 알 수있는 하드 코드 된 방법이 없다는 것입니다 ... "printline"옵션을 도입하기 위해 po2prop.py 파일을 조금 사용했습니다 ... 이를 수행하는 방법은 두 가지가 있습니다. 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) 

를 따라서는 (는 코드에 주석의 주석이 필요할 때)된다 :

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

간단합니다. 힌트 : 잊지 마세요 : 파일

관련 문제