I've been banging my head against this method in Flask for some time, and while it seems I'm making progress now, I've just happened upon something that baffles me to no end. Here is the method I'm calling:
我已经在Flask中反对这种方法了一段时间了,虽然现在看来我正在取得进展,但我发现了一些困扰我的东西。这是我正在调用的方法:
@app.route('/facedata/<slug>', methods=["POST"])
def facedata(slug):
if request.method == "POST":
try:
post = Post.objects.get_or_404(slug=slug)
data = [float(item) for item in request.form.getlist('emotions[]')]
post.face_data.append(data)
post.save()
except:
traceback.print_exc(file=sys.stdout)
For a long time I was getting errors in here that would then be caught in the heroku logs. Currently there are no errors, implying that it doesn't reach the except loop, but even worse, there are still 500 errors. Specifically the 500 errors I get are:
很长一段时间我在这里遇到错误,然后会被heroku日志记录下来。目前没有错误,暗示它没有达到except循环,但更糟糕的是,仍然有500个错误。特别是我得到的500个错误是:
heroku[router]: at=info method=POST path=/facedata/StripedVuitton host=cryptic-mountain-6390.herokuapp.com fwd="18.111.90.180" dyno=web.2 connect=4ms service=39ms status=500 bytes=291
I'm sending these POST
requests via AJAX in this method:
我在这个方法中通过AJAX发送这些POST请求:
var slug = document.getElementById("hidden-slug").getAttribute("value");
data = {emotions: lRes};
$.ajax({
type: "POST",
data: data,
url: document.location.origin + "/facedata/" + slug,
success: function(){
console.log("Success!");
}
});
Quite honestly I just don't know how to continue debugging this problem. It doesn't make a lot of sense to me to be getting a traceback without an exception, but maybe I'm just being naive.
老实说,我只是不知道如何继续调试这个问题。在没有例外的情况下获得追溯对我来说没有多大意义,但也许我只是天真。
I'm using mongoengine on top of MongoHQ on Heroku if that's relevant.
如果这是相关的话,我在Heroku上使用MongoHQ上面的mongoengine。
1 个解决方案
#1
45
After beating my head against this some more I finally figured it out thanks to the awesome people on the pocoo google group (I have since learned that there is a separate list for flask). Firstly, I needed to turn on the PROPAGATE_EXCEPTIONS
option in my app configuration (http://flask.pocoo.org/docs/config/#builtin-configuration-values).
在打了我的脑袋之后,我终于弄明白了,感谢pocoo google小组中的人们(我已经了解到烧瓶有一个单独的列表)。首先,我需要在我的应用配置中打开PROPAGATE_EXCEPTIONS选项(http://flask.pocoo.org/docs/config/#builtin-configuration-values)。
After that was done I realized there was an issue with not returning a response from a view function, which Flask interpreted this method as. Since that was the case, this issue was resolved by just adding:
在那之后,我意识到没有从视图函数返回响应的问题,Flask将此方法解释为。既然如此,只需添加以下内容即可解决此问题:
return jsonify(result={"status": 200})
To the end of the try
block. I hope this helps someone in a similar situation in the future.
到try块的末尾。我希望这可以帮助将来处于类似情况的人。
#1
45
After beating my head against this some more I finally figured it out thanks to the awesome people on the pocoo google group (I have since learned that there is a separate list for flask). Firstly, I needed to turn on the PROPAGATE_EXCEPTIONS
option in my app configuration (http://flask.pocoo.org/docs/config/#builtin-configuration-values).
在打了我的脑袋之后,我终于弄明白了,感谢pocoo google小组中的人们(我已经了解到烧瓶有一个单独的列表)。首先,我需要在我的应用配置中打开PROPAGATE_EXCEPTIONS选项(http://flask.pocoo.org/docs/config/#builtin-configuration-values)。
After that was done I realized there was an issue with not returning a response from a view function, which Flask interpreted this method as. Since that was the case, this issue was resolved by just adding:
在那之后,我意识到没有从视图函数返回响应的问题,Flask将此方法解释为。既然如此,只需添加以下内容即可解决此问题:
return jsonify(result={"status": 200})
To the end of the try
block. I hope this helps someone in a similar situation in the future.
到try块的末尾。我希望这可以帮助将来处于类似情况的人。