What is the “405 Method Not Allowed” in this Python code (Google engine)?

I am new to python and I am trying to create an application that copies step by step what was taught earlier in my class, but I get the error "405 Method Not Allowed".

Here is what the professor did: enter image description here

Here is what I did:

enter image description here

Can someone tell me which of the code below is causing this error? 405 Method not allowed? I do not see the difference between what I did and what the professor taught. Indentation is also good (here is the main.py file https://docs.google.com/open?id=0B8TXLR_e14aCVDFfdlpYSU9DNDg ).

Thanks in advance for your help!

Here is 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)
+3
source share
6 answers

. 405.

? 405 "". ...:)

import webapp2

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):
    # Error here: mistyped get instead of post :)
    def get(self):
        text = self.request.get("text")
        self.response.out.write(text)


app = webapp2.WSGIApplication([('/', MainHandler),
                               ('/rot13', Rot13Handler)],
                              debug=True)

, , :

app = webapp2.WSGIApplication([('/', MainHandler),
                               ('/rot13', MainHandler)],
                              debug=True)

EDIT (, @Nick Johnson)

, GAE.

  • app.yaml main.py?
  • Google AppEngine?
  • , , , , .
  • , , ? , .
+4

Python - Udacity , AppEngine post.

, , , INDENTION.

Notepad ++ , , 405. Netbean IDE Python, IDE , , POST GET, Notepad ++, , .

+9

. . :

def post(self):

"" , . , . . , IDE python, , Wing IDE.

+2

Notepad ++. , Python IDLE, , :)

+1

Notepad ++. , , , . Python IDLE. . @Aris , "" Python IDE - .

0

I had the same problem with my code, which was fixed when I changed the order of the handlers. I went through several different SO answers, checking for errors in the definition of the handler, indentation, and finally fixed it when viewing the order of the handlers.

0
source

All Articles