From 098b79a8bfba97ff757f425a9b83fa893db42262 Mon Sep 17 00:00:00 2001 From: 38elements Date: Thu, 4 May 2017 23:43:17 +0900 Subject: [PATCH] Add troubleshooting.md --- docs/index.rst | 1 + docs/sanic/troubleshooting.md | 54 +++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 docs/sanic/troubleshooting.md diff --git a/docs/index.rst b/docs/index.rst index 80e7e70f..035b2708 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -24,6 +24,7 @@ Guides sanic/testing sanic/deploying sanic/extensions + sanic/troubleshooting sanic/contributing diff --git a/docs/sanic/troubleshooting.md b/docs/sanic/troubleshooting.md new file mode 100644 index 00000000..e8cfec01 --- /dev/null +++ b/docs/sanic/troubleshooting.md @@ -0,0 +1,54 @@ +# Troubleshooting + +## ERROR: NoneType: None in console + +The message `ERROR: NoneType: None` is caused by timeout error caused by request not occuring in Keep-Alive. +There are two methods not to display a message. + +* Invalidating Keep-Alive. + +```python +from sanic.config import Config +Config.KEEP_ALIVE = False +``` + +* Setting custom protocol. + +```python +from time import time +from sanic import Sanic +from sanic.response import json +from sanic.config import Config +from sanic.server import HttpProtocol +from sanic.exceptions import RequestTimeout + + +class CustomHttpProtocol(HttpProtocol): + + def connection_timeout(self): + current_time = time() + time_elapsed = current_time - self._last_request_time + if time_elapsed < self.request_timeout: + time_left = self.request_timeout - time_elapsed + self._timeout_handler = ( + self.loop.call_later(time_left, self.connection_timeout)) + else: + if self._request_handler_task: + self._request_handler_task.cancel() + if self._total_request_size == 0: + self.transport.close() + else: + exception = RequestTimeout('Request Timeout') + self.write_error(exception) + + +app = Sanic() + + +@app.route("/") +async def handler(request): + return json({"hello": "world"}) + +if __name__ == "__main__": + app.run(host="127.0.0.1", port=8000, protocol=CustomHttpProtocol) +```