AttributeError: 'NotFound' object has no attribute 'encode'

AttributeError: 'NotFound' object has no attribute 'encode'

当用户使用具有超过 3 个子路径的 URL 运行我的 Flask 应用程序时,例如 "domain.com/var1/var2/var3/var4",它会抛出以下错误:

Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1478, in    full_dispatch_request
response = self.make_response(rv)
File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1574, in make_response
rv = self.response_class(rv, headers=headers, status=status)
File "/usr/local/lib/python2.7/site-packages/werkzeug/wrappers.py", line 758, in __init__
self.status = status
File "/usr/local/lib/python2.7/site-packages/werkzeug/wrappers.py", line 862, in _set_status
self._status = to_native(value)
File "/usr/local/lib/python2.7/site-packages/werkzeug/_compat.py", line 111, in to_native
return x.encode(charset, errors)
AttributeError: 'NotFound' object has no attribute 'encode'

它适用于少于或等于 3 个子路径的 url,例如 "domain.com/var1/var2/var3",但我有 url 的路由 1、2 和3 个子路径。

如何让我的应用转到 404 页面未找到方法而不是抛出此错误?

谢谢!

编辑.. 这是我正在使用的路由方法的 pastebin。 http://pastebin.com/kjYsqk9n

抱歉,我无法提供这个问题的示例,这真的很奇怪,我不知道如何自己重现它。我的其他烧瓶应用程序工作正常,这个不行。如果有人需要澄清,请告诉我...感谢您的帮助!

找出返回错误的原因。结果我在这一行的末尾传递了错误对象而不是“404”:

return render_template("error.html", usa=usa, canada=canada, breadcrumbs=breadcrumbs, error_code=e), 404

谢谢!