0

In all of my view functions if i 'methods=['POST'] for example:

@app.route( '/file', methods=['POST'] )

i receive the error:

    Error: 405 Method Not Allowed
Sorry, the requested URL 'http://superhost.gr/downloads/file' caused an error:

Why Bottle gives me this error message?

1 Answers1

3

I'd guess you get error when trying to get the view (GET). And that is result of your only allowing POST.

You should have

@app.route( '/file', method=['POST', 'GET'] )

or a separate handler

@app.route( '/file', method=['GET'] )

Update: looks like there was a typo in your example that I copied over. 'methods' should be 'method'.

Update2: Below is a working example:

from bottle import Bottle, run

app = Bottle()

@app.route('/file', method=['GET', 'POST'])
def file():
    return "Hello!"

run(app, host='localhost', port=8080)
Eduard
  • 897
  • 5
  • 11
  • I was under the impression 'GET' was implied. I did add it though as you have suggested but i'am still receiving the same error mentioned. – Νικόλαος Βέργος Sep 23 '18 at 13:43
  • @ΝικόλαοςΒέργος, see update. And yes 'GET' is default, but when you override it you should explicitly specify all methods you want to listen to. Because you literally override default value ('GET'). You can check bottle code here: https://github.com/bottlepy/bottle/blob/master/bottle.py#L884 – Eduard Sep 23 '18 at 14:32
  • Well, i did specify all the methods as `method=['POST', 'GET']` but still i'am getting the error `Method NOT allowed' – Νικόλαος Βέργος Sep 23 '18 at 14:54
  • @ΝικόλαοςΒέργος, see code sample in update. If this results in same then you are doing something else wrong. – Eduard Sep 23 '18 at 15:51
  • I cant believe that "that" was the error. I moved from Flask to Bottle and thats why i had it like 'methods'. Thank you very much! Can you help me with another silly error iam getting if you want? https://stackoverflow.com/questions/52463652/what-is-the-way-to-reference-an-image-from-within-a-bottle-template – Νικόλαος Βέργος Sep 23 '18 at 16:17