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

405 Method Not Allowed is returning a HTML response instead of JSON #362

Open
jkehler opened this issue Oct 15, 2014 · 6 comments
Open

405 Method Not Allowed is returning a HTML response instead of JSON #362

jkehler opened this issue Oct 15, 2014 · 6 comments

Comments

@jkehler
Copy link

jkehler commented Oct 15, 2014

Wouldn't best practices be that all responses be returned in JSON format? Is there any way to override this behavior?

HTTP/1.0 405 METHOD NOT ALLOWED
Content-Type: text/html
Allow: OPTIONS, GET, HEAD
Content-Length: 178
Server: Werkzeug/0.9.6 Python/3.4.2
Date: Wed, 15 Oct 2014 02:52:37 GMT

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>405 Method Not Allowed</title>
<h1>Method Not Allowed</h1>
<p>The method is not allowed for the requested URL.</p>

I think it should be returning something like this instead.

HTTP/1.0 405 METHOD NOT ALLOWED
Content-Type: application/json
Allow: OPTIONS, GET, HEAD
Content-Length: 178
Server: Werkzeug/0.9.6 Python/3.4.2
Date: Wed, 15 Oct 2014 02:52:37 GMT

{
     "message": "The method is not allowed for the requested URL.",
     "status": 405
}
@jpoehnelt
Copy link
Contributor

Probably won't be able to change this within flask-restless. A workaround would be to allow the method via the api manager and use a preprocessor to return the json error response.

jkehler added a commit to jkehler/flask-restless that referenced this issue Oct 17, 2014
@jkehler
Copy link
Author

jkehler commented Oct 17, 2014

I have submitted pull request #366 that has fixed this issue. All http exceptions are now returned in JSON format without requiring manual implementation with preprocessors.

@jfinkels
Copy link
Owner

I may have a problem with that pull request, see the comment I am about to post there.

@jfinkels jfinkels added the bug label Oct 21, 2014
jkehler added a commit to jkehler/flask-restless that referenced this issue Oct 21, 2014
@jfinkels
Copy link
Owner

jfinkels commented Feb 3, 2015

I have closed the pull request suggested by @jkehler, but I'm happy to review another one that makes the changes I suggested in the discussion there.

@jfinkels
Copy link
Owner

jfinkels commented Mar 2, 2016

This should be fixable if we require Flask 1.0, since pallets/flask#503 has been fixed, i.e. we can use blueprint-local error-handling to create an error-handler for HTTP 405 responses that responds with a JSON API document.

@jfinkels
Copy link
Owner

The versioning for Flask became weird; pallets/flask#503 seems to have been included in Flask 0.11.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants