Flask - The method is not allowed for the requested URL

Hello, I’m a student and I’ve just started with the POSTMAN application. I’m trying to set up a python server using Flask so that I can create an API to share the results of home automation experiments (e.g. arduino).

Unfortunately I have a problem with my POST request, I don’t want to use JSON formats but “x-www-form-urlencoder”. When I send the request I get an error 405 “METHOD NOT ALLOWED”.

really don’t understand where this problem can come from as my GET request is working properly (I’m sure it’s a stupid mistake :pensive:…) .

It would be really great if one of you could unblock me!

I am enclosing the different elements of my problem.

— Python - Flask script —

— Postman GET query —

— Postman Post query —


Thank you in advance!

I’m not even going to begin to tell you anything about Python or Flask but that looks like you are sending both the GET and POST to the same route.

I think be default, it’s set to receive GET requests but you would need to tell it that its for other methods.

I would suppect that’s the reason for the 405 status code.

Add something like this I think but probably need more to handle the params and/or body:

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

https://www.flaskapi.org/#requests

1 Like

The given link is broken but It worked. Thanks.

Seems like that project has moved in the last 3 years :sweat_smile:

I think this is the right set of docs now:

https://flask.palletsprojects.com/en/3.0.x/