Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Flask's abort(404) does not work with Zero #133
Comments
|
And as usual, I finally figured it out myself right after posting the question: from flask import make_response
def handler(name):
if not VIDEO_PATH.joinpath(name).exists():
return make_response("", 404)
# ...I still think |
I've made a Python API file for fetching a resource. If the resource doesn't exist, I want to return "404 Not Found". I have tried Flask's
abort(404), but the NotFound error is caught at some point and I get a TypeError instead, resulting in a 500 Server Error from Zero. Here is the stack trace: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. [2020-06-05 20:40:01,549] ERROR in app: Exception on /video/foobar/ [GET] Traceback (most recent call last): File "/home/tomas/.local/lib/python3.8/site-packages/flask/app.py", line 2446, in wsgi_app response = self.full_dispatch_request() File "/home/tomas/.local/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request return self.finalize_request(rv) File "/home/tomas/.local/lib/python3.8/site-packages/flask/app.py", line 1967, in finalize_request response = self.make_response(rv) File "/home/tomas/.local/lib/python3.8/site-packages/flask/app.py", line 2096, in make_response raise TypeError( TypeError: The view function did not return a valid response. The function either returned None or ended without a return statement.Is this a bug? Or is there a different way to do it?