Forums

Post method not allowed?

Trying to post something in my webapp I got the following response headers:

HTTP/1.1 405 METHOD NOT ALLOWED Server: nginx/1.2.5 Date: Wed, 09 Jan 2013 23:28:09 GMT Content-Type: text/html Content-Length: 183 Connection: keep-alive Allow: HEAD, OPTIONS, GET

Post method not allowed?

problem persists even if I put methods=['POST', 'GET'] in route arguments

problem solved.

What was the problem, for anybody who finds this thread in the future?

I am getting this error message now and working on it. Any info is appreciated!

Hi there -- did you manage to solve it? I just took a look at your web app, and it looks fine now. When I checked our your error logs -- you can see them yourself here -- I saw that there was some kind of problem in the app that you sorted out about 40 minutes after you made this post.

If the problem's still occurring, could you show me a URL that demonstrates it?

Hi, I'm hitting by this problem now, can anybody tell me how to solve it? I just try to post a message to my url "hyin.pythonanywhere.com", I suppose my wsgi code should work but the website just returns me a “405” immediately.

Please help! thanks.

The anwers depends on which framework you're using. For example, on Flask you should have something like this:

@app.route('/login', methods=['GET', 'POST'])
def login():
    if request.method == 'POST':
        do_the_login()
    else:
        show_the_login_form()

That's taken from this section of the Flask docs where there's more detail.

For other frameworks you'll likely need to do something similar. The PA hosting should be method-agnostic (at least for standard methods) so the issue is almost certainly something in your application.

Whichever framework you use, don't forget to reload the application after making the change, or the change won't take effect.

Hi hyin -- are you seeing anything in your error logs? You can access them here.

@app.route("/profile/<string:Sno>", methods=['GET', 'POST']) how can i use in pythonanywhere because gives error local server error.

what's the full error traceback?

I don't understand why it gives me the error "Method Not Allowed The method is not allowed for the requested URL."

@app.route('/', methods=['POST']) def hello_world(): return 'Hello from Flask!'

Do you try to make GET request on it while it allows only POST?

.

@route('/selectFormula')
def selectFormula():
    return template("selectFormula.html")

I am having my bottle app route be /selectFormula so my page will open with this specific route, but I keep getting 405 error method not allowed when I press enter.

[edit by admin: formatting]

It sounds like you've configured your HTML form to send a POST request, so you should change your @route to allow those kinds of requests -- see the Bottle documentation here.