I'm a python newbie and I'm trying to build an app copying step by step what was taught earlier in my class, but I'm getting the "405 Method Not Allowed" error.
Here what the professor did:
Here what I did:
Could someone point me what in the code below is the cause of this error "405 Method Not Allowed"? I can not see difference between what I did and what the professor taught. The indentation is also ok (here is the main.py file https://docs.google.com/open?id=0B8TXLR_e14aCVDFfdlpYSU9DNDg).
Thanks in advance for any help!
Here my code:
form= """
<html>
<head>
<title>Unit 2 Rot 13</title>
</head>
<body>
<h2>Enter some text to ROT13:</h2>
<form method="post" action="/rot13">
<textarea name="text"
style="height: 100px; width: 400px;"></textarea>
<br>
<input type="submit">
</form>
</body>
</html> """
class MainHandler(webapp2.RequestHandler):
def get(self):
self.response.out.write(form)
class Rot13Handler(webapp2.RequestHandler):
def post(self):
text = self.request.get("text")
self.response.out.write(text)
app = webapp2.WSGIApplication([('/', MainHandler), ('/rot13', Rot13Handler)],
debug=True)
I had the same problem with my code which was fixed when I rearranged the order of the handlers. Went through several different SO answers checking for errors in Handler definition, indentation and finally fixed it on looking at the order of the handlers.
I am just trying Python following Udacity's online course and met similar issue that the AppEngine unable to find the post method.
And finally it turns out that the root cause is the INDENTION.
I used Notepad++ as the editor for the small project and it just can't work, keep throwing the 405 error. then I copy and paste the code to Netbean IDE with Python plugin installed, the IDE showed that it was wrong indention that made the POST method an inner method of GET method, which could not be found in Notepad++, although it looked like the indention been handled well.
had the same problem. The issue was indentation again. When defining:
if I used 'tab' for indentation it was not working. When I used spaces it did. The error logs showed nothing. To avoid issues like this, you can use a python IDE, like Wing IDE.
I had the same issue with Notepad++. Only thing that I changed with the Python IDLE was to replace some spaces with a tab and it worked fine :)
The code is correct and works fine. You need to look elsewhere for an explanation of this 405 error.
EDIT
Have you posted your actual code? This code below will give you a 405 Method not Allowed error when you click submit. It has a subtle error in it... :)
And the same would happen if your routing is incorrectly typed, as in:
EDIT (Thanks, @Nick Johnson)
If none of the above works, consider starting from scratch and check your GAE set-up.
app.yaml
file alongside themain.py
module?Ran into the same problem using Notepad++ . Took me days to figure out what was wrong till I read this. Switched to using Python IDLE. Works like a charm. I'll echo @Aris and say that using a 'traditional' Python IDE is the best way to go.