2014-11-22 1 views
0

간단한 Python 통화를 테스트하는 데 문제가 있습니다 테스트를 실행하면 항상이 오류가 발생합니다 코드에서 아마도 null 객체에 액세스하고 있습니다. 하지만 어디 어떤 아이디어? 고맙습니다 !WebPy 'NoneType'객체에 '__getitem__'속성이 없습니다.

#!/usr/bin/env python 
import web 
import xml.etree.ElementTree as ET 

tree = ET.parse('user.xml') 
root = tree.getroot() 

urls = (
    '/users', 'list_users', 
    '/users/(.*)', 'get_user' 
) 

app = web.application(urls, globals()) 

class list_users: 
    def GET(self): 
     output = 'users:['; 
     for child in root: 
      print 'child', child.tag, child.attrib 
      output += str(child.attrib) + ',' 
     output += ']'; 
     return output 

class get_user: 
    def GET(self, user): 
     for child in root: 
      if child.attrib['id'] == user: 
       return str(child.attrib) 

if __name__ == '__main__': 
    app.run() 
+3

** 전체 ** 추적을 제공해야합니다. –

답변

0

user.xml 파일을이 Python 파일과 동일한 디렉토리에 저장 했습니까?

코드를 복사하고 실행했습니다. 작동합니다. 따라서 문제는 아마 web.py를 설치하는 것입니다.

그냥 webpy과이 작업을 수행하기 위해 관련된 모든 폴더를 삭제 :

1) web.py 다운로드 - 폴더를 here에서.

2) 여기에서 'web'폴더를 현재 디렉토리에 저장하십시오.

3) 이제 프로그램을 실행하면 제대로 작동합니다.

관련 문제