[英]Repeated ERROR: NoneType in Sanic App
I keep getting Error: Nonetype
from a Sanic app and I cannot identify the reason. 我不断从Sanic应用程序获得Error: Nonetype
,我无法确定原因。
My code: 我的代码:
from sanic import Sanic
from sanic.response import json, text
from sanic.request import RequestParameters
from parse_data import ParseData
pdata = ParseData()
app = Sanic('sanic_sms')
app = Sanic(__name__)
@app.route("/", methods=["POST",])
async def test(request):
data = {}
if request.form:
data = request.form
elif request.json:
data = request.json
result = pdata.prepare_output(data.get('text'))
resp = json(result)
resp.headers["Access-Control-Allow-Origin"] = "*"
resp.headers["Access-Control-Allow-Headers"] = "Content-Type,Authorization"
return resp
app.run(host="0.0.0.0", port=8002)
2017-05-13 15:10:03,454: INFO: Goin' Fast @ http://0.0.0.0:8002 2017-05-13 15:10:03,454:信息:Goin'Fast @ http://0.0.0.0:8002
2017-05-13 15:10:03,456: INFO: Starting worker [30662] 2017-05-13 2017-05-13 15:10:03,456:INFO:起始工作者[30662] 2017-05-13
15:11:19,579: ERROR: NoneType 15:11:19,579:错误:无类型
How can I solve this? 我怎么解决这个问题?
It was probably some bug in some previous version of Sanic (I got that behavior on version 0.4.0). 这可能是某些先前版本的Sanic中的一些错误(我在版本0.4.0上得到了这种行为)。
The app threw NoneType 408
at a constant rate. 该应用程序以恒定速率投掷NoneType 408
。
Solved it by tempering the KEEP_ALIVE
setting of the Config
dictionary: 通过调整Config
字典的KEEP_ALIVE
设置解决它:
from sanic.config import Config
Config.KEEP_ALIVE = False
app = Sanic(__name__)
In the current version (0.7.0) this seems to have been fixed. 在当前版本(0.7.0)中,这似乎已得到修复。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.