Google App Engine python - 自定义未定义

时间:2010-05-16 20:42:27

标签: python google-app-engine

我有一个映射到此类ChatMsg的请求 它接受3个get变量,用户名,房间名和消息。但它在这最后一行失败了。

class ChatMsg(webapp.RequestHandler): # this is line 239
    def get(self):
        username = urllib.unquote(self.request.get('username'))
        roomname = urllib.unquote(self.request.get('roomname')) # this is line 242

当它试图分配房间名时,它告诉我:

<type 'exceptions.NameError'>: name 'self' is not defined
Traceback (most recent call last):
  File "/base/data/home/apps/chatboxes/1.341998073649951735/chatroom.py", line 239, in <module>
    class ChatMsg(webapp.RequestHandler):
  File "/base/data/home/apps/chatboxes/1.341998073649951735/chatroom.py", line 242, in ChatMsg
    roomname = urllib.unquote(self.request.get('roomname'))

到底是什么让自己没有被定义

1 个答案:

答案 0 :(得分:3)

这应该是缩进问题。回溯显示错误不在get()方法中。在定义类时会收到NameError异常。 尝试执行以下代码,您将得到与您相同的异常。

class ChatMsg(object): # this is line 239
    def get(self):
        username = urllib.unquote(self.request.get('username'))
    roomname = urllib.unquote(self.request.get('roomname')) # this is line 242