我得到这个错误:
HTTP 599: Connection closed [E 130405 11:43:14 web:1031] Uncaught exception GET /networks/1/sensors/1/alarm (127.0.0.1)
执行以下代码时:
from tornado.stack_context import ExceptionStackContext
def handle_exc(*args):
print('Exception occured')
return True
@tornado.gen.engine
def check_status_changes(netid, sensid):
como_url = "".join(['http://131.114.52:44444/ztc?netid=', str(netid), '&sensid=', str(sensid), '&start=-5s&end=-1s'])
http_client = AsyncHTTPClient()
response = yield tornado.gen.Task(http_client.fetch, como_url)
if response.error is not None:
print("Terzo")
print response.error
with ExceptionStackContext(handle_exc):
response.rethrow()
else:
print('Handle request')
for line in response.body.split("\n"):
if line != "":
#net = int(line.split(" ")[1])
#sens = int(line.split(" ")[2])
#stype = int(line.split(" ")[3])
value = int(line.split(" ")[4])
print value
yield value
return
class AlarmHandler(BaseHandler):
@tornado.web.authenticated
@tornado.web.asynchronous
@tornado.gen.engine
def get(self, netid, sensid):
self.lock_tables("read", ['devices'])
status = self.db.get("SELECT status from devices \
WHERE id=%s AND network_id=%s", sensid, netid)
print("Primo")
print status
try:
periodic = tornado.ioloop.PeriodicCallback(check_status_changes(netid, sensid), 5000)
value = periodic.start()
print("Secondo")
print value
except:
print("Quarto")
periodic.stop()
self.finish()
return
if value != status['status']:
self.lock_tables("write", ['devices'])
self.db.execute("UPDATE devices SET status=%s \
WHERE id=%s AND network_id=%s", value, netid, sensid)
self.unlock_tables()
self.notice("Status changed")
在类AlarmHandler
中有一个称为check_status_changes
的周期例程。在这个函数中,当有response.error时,我获得标题的错误。
如何设置if错误条件以返回类并管理该情况?谢谢您。
其他信息
如果我做一个龙卷风的屏幕,我看到这个:
Primo
{'status': None}
Secondo
None
Terzo
HTTP 599: Connection closed
Exception occured
所以,我认为程序在返回异常之前关闭连接!
在html控制台中,我看到这个错误:
File "./wsn.py", line 226, in check_status_changes for line in response.body.split("\n"): AttributeError: 'NoneType' object has no attribute 'split'
你提出了一个例外:
这将是一个
Uncaught Exception
。您应该编写此代码来处理异常而不引发异常。E、 记录错误信息并中止数据库更新。相关问题 更多 >
编程相关推荐