【问题标题】:Python HTTP 599: Connection closed (Tornado)Python HTTP 599:连接关闭(龙卷风)
【发布时间】:2013-04-05 09:49:33
【问题描述】:

我收到此错误:

HTTP 599:连接已关闭 [E 130405 11:43:14 web:1031] 未捕获 异常 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 错误条件以返回课堂并管理情况?谢谢。

其他信息

如果我制作 Tornado 屏幕,我会看到:

普里莫

{'状态':无}

第二个

没有

泰尔佐

HTTP 599:连接关闭

发生异常

所以,我认为程序在异常 rethtow 之前关闭了连接!

在 html 控制台中我看到了这个错误:

文件“./wsn.py”,第 226 行,在 check_status_changes 对于 response.body.split("\n") 中的行:AttributeError: 'NoneType' object has no attribute 'split'

【问题讨论】:

    标签: python tornado http-error connection-close


    【解决方案1】:

    您正在引发异常:

    if response.error:
            print("Terzo")
            print response.error
            raise Exception(response.error)
            return
    

    这将是一个Uncaught Exception。您应该对此进行编码以处理异常而不引发异常。例如。记录错误消息并中止数据库更新。

    【讨论】:

    • 好的 MattH 我试过这个解决方案stackoverflow.com/a/7623570/1353274你在 python 聊天中给我。我试过了,但错误是一样的......在互联网上搜索我发现在旧的 Tornado 版本中有类似的错误......可能是我的问题吗?如何获得我的 Tornado 版本?但是我用你的解决方案编辑了这个问题。
    猜你喜欢
    • 1970-01-01
    • 2012-01-13
    • 1970-01-01
    • 1970-01-01
    • 2014-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多