2013-03-01 44 views
0

我遇到問題。Tornado中的self.finish()錯誤

我有這部分代碼:

 if command in ['ON', 'OFF', 'TOGGLE']: 
     ret['success'] = "The %s command has been succesfully sent!" % (command.upper()) 
     self.write(tornado.escape.json_encode(ret)) 
     self.finish() 
    elif command == 'HOWMANY': 
     opcodegroupr = "A0" 
     opcoder = "85" 
    elif command == 'IDENTIFY': 
     opcodegroupr = "A0" 
     opcoder = "81" 

我想開,關,切換完成處理程序命令。相反,對於命令howmany和確定我會爲其他闡述創建新變量。

但是,當我發送例如在命令我得到這個錯誤:

File "./wsn.py", line 1024, in get 
'&opcode_group=', opcodegroupr, 
UnboundLocalError: local variable 'opcodegroupr' referenced before assignment 

像self.finish()不關閉處理。

問題在哪裏?

非常感謝。

回答

0

只有這部分代碼,我假設你錯過了回報。 self.finish()關閉請求,但不從函數返回。

if command in ['ON', 'OFF', 'TOGGLE']: 
    ret['success'] = "The %s command has been succesfully sent!" % (command.upper()) 
    self.write(tornado.escape.json_encode(ret)) 
    self.finish() 
    return   # self.finish() finishes the request - doesn't return 
else ... 
+0

是的!!!謝謝!! – sharkbait 2013-03-01 16:10:03