好的。
我们正在使用Flask应用。由gunicorn + Nginx在docker容器中提供。我们的记录器大约每24个记录就有1-2次,记录器显示以下消息:
Dec 31 00:27:36 Computer logger: [12/31/2019 08:27:36] backend ERROR: 404 Not Found: The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again. Traceback (most recent call last): File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1949, in full_dispatch_request rv = self.dispatch_request() File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1925, in dispatch_request self.raise_routing_exception(req) File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1907, in raise_routing_exception raise request.routing_exception File "/usr/local/lib/python3.6/site-packages/flask/ctx.py", line 350, in match_request result = self.url_adapter.match(return_rule=True) File "/usr/local/lib/python3.6/site-packages/werkzeug/routing.py", line 1799, in match import pdb werkzeug.exceptions.NotFound: 404 Not Found: The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.
这会影响什么或造成什么是完全神秘的,而回溯丝毫没有帮助。面向用户的方面没有明显的变化。我已经尝试了很多事情,包括启动应用程序。在调试模式下。我最近的尝试是进入/usr/local/lib/python3.6/site-packages/werkzeug/routing.py
本身并更改错误的行为。但是,发生的是,上面记录的消息只是打印出了我的代码更改-但似乎并没有真正在运行这些更改。 (即-不管我如何更改该文件,所有内容看上去都以完全相同的方式运行。相反,更改本身会被记录下来(而不是运行更改后的代码的效果))。
如何像这样调试无响应的werkzeug 404错误?我缺少什么选项/设置/方法?为什么会忽略对routing.py
代码的更改(例如),而将其打印输出到屏幕上(就像Python所做的只是打印line x
和line y
之间的代码块一样)。
我认为最好的方法是检查Nginx日志。但是,您可以在烧瓶上进行处理并记录错误,甚至可能显示如下错误页面:
from flask import Flask, render_template
app = Flask(__name__)
# app name
@app.errorhandler(404)
# inbuilt function which takes error as parameter
def not_found(e):
# defining function
return render_template("404.html")
更多详细信息here