什么是生产“405方法不允许”在这个Python代码(谷歌应用程序引擎)? [英] What is producing "405 Method Not Allowed" in this python code (google app engine)?

查看:249
本文介绍了什么是生产“405方法不允许”在这个Python代码(谷歌应用程序引擎)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名python新手,我正在尝试逐步构建一个应用程序,以便在我的课程中早些时候教导,但是我收到了405方法不允许的错误。



这里教授做了什么:



在这里我做了:


有人能指出我在下面的代码中是什么原因导致了这个错误405方法不允许 ?我看不出教授所教的内容与我所做的有什么不同。
缩进也可以(这里是main.py文件 https:// docs .google.com /开?ID = 0B8TXLR_e14aCVDFfdlpYSU9DNDg )。



在此先感谢您的帮助!



这里是我的代码:

  form =
< html>
< head>
< title> Unit 2 Rot 13< title>
< / head>

< body>
< h2>输入一些文字到ROT13:< / h2>
< form method =postaction =/ rot13>
< textarea name =text
style =height:100px;宽度:400px;>< / textarea>
< br>
< input type =submit>
< / form>
< / body>

< / html>

class MainHandler(webapp2.RequestHandler):
def get(self):
self。 response.out.write(form)
$ b $ 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)


解决方案

精细。你需要在别处寻找这个405错误的解释。

编辑



你有没有发布你的实际代码?当您点击提交时,下面的代码会给你一个405方法不允许的错误。它有一个微妙的错误...)

  import webapp2 

form =
< html>
< head>
< title> Unit 2 Rot 13< / title>
< / head>

< body>
< h2>输入一些文字到ROT13:< / h2>
< form method =postaction =/ rot13>
< textarea name =text
style =height:100px;宽度:400px;>< / textarea>
< br>
< input type =submit>
< / form>
< / body>

< / html>

class MainHandler(webapp2.RequestHandler):
def get(self):
self。 response.out.write(表单)
$ b $ class class Rot13Handler(webapp2.RequestHandler):
#此处错误:错误类型获取而不是post :)
def get(self):$ (文本)

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

如果路由输入错误,则会发生同样的情况,例如:

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

编辑(谢谢,@Nick Johnson)



如果以上任何一项都不起作用,请考虑从头开始并检查您的GAE设置。


  1. 您是否有一个有效的 app.yaml 文件以及 main.py 模块?

  2. 您是否可以在标准Google AppEngine安装中运行留言板演示应用程序?

  3. 如果没有,请发布错误消息(如果有)以及您正在运行的系统的详细信息。

  4. 如果您能够运行留言簿,您可以尝试通过编辑该应用程序来重建应用程序吗?我发现这在过去对我有用。


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)

解决方案

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... :)

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)

And the same would happen if your routing is incorrectly typed, as in:

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

EDIT (Thanks, @Nick Johnson)

If none of the above works, consider starting from scratch and check your GAE set-up.

  1. Do you have a valid app.yaml file alongside the main.py module?
  2. Are you able to run the guestbook demo app in the standard Google AppEngine installation?
  3. If not, post the error messages, if any, as well as the details of the system that you are running it on.
  4. If you are able to run the guestbook, can you try and rebuild your application by editing that one? I have found that this has worked for me in the past.

这篇关于什么是生产“405方法不允许”在这个Python代码(谷歌应用程序引擎)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆