WebPy 'NoneType' object has no attribute '__getitem__'

247 views Asked by At

I'm having an issue testing a simple Python Rest call When I run the test I always get this error Something in the code perhaps I'm accessing a null object but where Any idea ? thank you !

#!/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()
1

There are 1 answers

0
boltthrower On

Have you made the user.xml file and saved it in the same directory as this Python file?

I copied your code and ran it, it works. So the problem is probably in installing web.py.

Just delete all folders related to webpy and do this:

1) Download web.py - the folder from here.

2) From this, save the 'web' folder into your current directory.

3) Now run your program, it should work.