Sanic: What's main for " ERROR: NoneType" in trace print?

Created on 3 Mar 2017  Â·  9Comments  Â·  Source: sanic-org/sanic

Ubuntu 16.04
python 3.5.2
sanic 0.4.1
vritualenv

# change work dir
os.chdir(os.path.dirname(os.path.realpath(__file__)))

app = Sanic(__name__)
app.static('/static', './static')

class DemoApi(HTTPMethodView):
    def get(self, request: Request):
        return json({'demo': 'success'})

app.add_route(DemoApi.as_view(), '/demo')

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=88, debug=True)

When I request '/demo', it is work ok.
But after a time, console trace this:

2017-03-03 11:43:28,657: INFO: Goin' Fast @ http://0.0.0.0:88
2017-03-03 11:43:28,684: INFO: Starting worker [14417]
2017-03-03 11:44:32,536: ERROR: NoneType

The "ERROR: NoneType" message occurs frequently, in debug and release mode.

What it's main and how to fix it?

Most helpful comment

I think custom error handler will solve.

All 9 comments

I have trying to catch the error like this:

class SentryErrorHandler(ErrorHandler):
    def default(self, request, exception):
        if exception is None:
            return text('unknown error occurred')
        print(str(exception))
        return super().default(request, exception)

app = Sanic(__name__, error_handler=SentryErrorHandler())

I got the output print like this:

2017-03-03 11:51:32,811: INFO: Goin' Fast @ http://0.0.0.0:88
2017-03-03 11:51:32,838: INFO: Starting worker [14515]
Request Timeout
2017-03-03 11:53:54,071: ERROR: NoneType

Executing <TimerHandle cancelled None created at /env/sanic/lib/python3.5/site-packages/sanic/server.py:105> took 24.346 seconds

It seems connection timeout?

I think this is a connection timeout.
I reproduced this behavior.
If you run the code below and access by browser, the behavior will occur.
If keep-alive is enabled, connection_lost() will not be executed.
self._ timeout_handler.cancel() will not be executed.
If there is no new request, Request Timeout will be raised.

from sanic import Sanic
from sanic.response import json
from sanic.config import Config

Config.REQUEST_TIMEOUT = 3 

app = Sanic()


@app.route("/")
async def test(request):
    return json({"hello": "world"})

if __name__ == "__main__":
    app.run(host="127.0.0.1", port=8000)

when query from one server to sanic, sanic print "ERROR: NoneType" and the server will print follow

Unsolicited response received on idle HTTP channel starting with "HTTP/1.1 408 Request Timeout\r\nConnection: close\r\nContent-Length: 22\r\nContent-Type: text/plain; charset=utf-8\r\n\r\nError: Request Timeout"; err=<nil>

how i can disable this message?

This message is output by this code.
If the Request Timeout Error Handler is set, the message does not occur.

thanks for reply.

I have tried
@app.exception(SanicException)
to catch all exception, but it not work.

Is it need to write like this?
@app.exception(NotFound, ServerError, RequestTimeout...)

Can I do it simple?

Hello sanic and thak you very much

2017-03-09 14:06 GMT+02:00 UltraGIS notifications@github.com:

thanks for reply.

I have tried
@app.exception(SanicException)
to catch all exception, but it not work.

Is it need to write like this?
@app.exception(NotFound, ServerError, RequestTimeout...)

Can I do it simple?

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/channelcat/sanic/issues/511#issuecomment-285334438,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AXWG59yCQHEqWjOwHDNeWiQKaOU_-Ej6ks5rj-tggaJpZM4MR1WZ
.

I think custom error handler will solve.

Thanks very much.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Souldat picture Souldat  Â·  3Comments

woutor picture woutor  Â·  3Comments

litelife picture litelife  Â·  3Comments

rainyear picture rainyear  Â·  3Comments

eseglem picture eseglem  Â·  4Comments