我有一个映射到此类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'))
到底是什么让自己没有被定义
答案 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