I am developing one simple code for force download now problem is that i'm not getting any error in GET method but getting error "405 Method Not Allowed" in post method request. My code for GET method.
@route('/down/<filename:path>',method=['GET', 'POST'])
def home(filename):
key = request.get.GET('key')
if key == "tCJVNTh21nEJSekuQesM2A":
return static_file(filename, root='/home/azoi/tmp/bottle/down/', download=filename)
else:
return "File Not Found"
When i request with key it is returning me file for download when it is get method http://mydomain.com/down/xyz.pdf?key=tCJVNTh21nEJSekuQesM2A
Now i used another code for handling POST methods
@route('/down/<filename:path>',method=['GET', 'POST'])
def home(filename):
key = request.body.readline()
if key == "tCJVNTh21nEJSekuQesM2A":
return static_file(filename, root='/home/azoi/tmp/bottle/down/', download=filename)
else:
return "File Not Found"
Now by using this code i cannot handle post method i.e. i am getting 405 Method Not Allowed error from server.
Any solution for this ?
If you are certain you need a POST request, chances are, you're just using the wrong endpoint on the server. Again, this can only be solved if you have proper documentation to show what methods are supported for each endpoint.
The Request Method' POST' Not Supported error is caused by a mismatch of the web browser configuration and the browser's URL format. In this case, the browser sends a URL request, the web server receives and recognizes the URL but cannot execute commands or grant access to the requested page.
Router takes only one method in method
parameter, not list of methods. Use several @route
decorators instead:
@route('/down/<filename:path>', method='GET')
@route('/down/<filename:path>', method='POST')
def home(filename):
pass
Check documentation for more information: http://bottlepy.org/docs/dev/routing.html#routing-order
UPDATE
Recent Bottle version allows to specify list of methods: http://bottlepy.org/docs/dev/api.html#bottle.Bottle.route
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With