Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flask's abort(404) does not work with Zero #133

Open
Hubro opened this issue Jun 5, 2020 · 1 comment
Open

Flask's abort(404) does not work with Zero #133

Hubro opened this issue Jun 5, 2020 · 1 comment

Comments

@Hubro
Copy link

Hubro commented Jun 5, 2020

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?

@Hubro
Copy link
Author

Hubro commented Jun 5, 2020

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 abort(404) should work though, so I'll keep this open as a feature request / bug report.

@Hubro Hubro changed the title How do I return a 404 Not Found error from a Python file? Flask's abort(404) does not work with Zero Jun 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant