看起来我还没有掌握异常处理的窍门。我不知所措:(以下代码有时会返回此错误:
File "applications/pingback/modules/plugin_h_pingback.py", line 190, in ping
db(table.id==id_).update(status=status)
UnboundLocalError: local variable 'status' referenced before assignment
我希望status
总是被分配一个值。会不会是其他一些异常被抛出(可能在内部try
)并且finally
掩盖了它?
...
try:
server_url = self._get_pingback_server(target)
except PingbackClientError, e:
status = e.message
else:
try:
server = xmlrpclib.ServerProxy(server_url)
status = server.pingback.ping(self.source, target)
except xmlrpclib.Fault, e:
status = e
finally:
db(table.id==id_).update(status=status) # <-- UnboundLocalError
...
谢谢,慧聪