我尝试在goold应用引擎中运行代码片段,并发现一个奇怪的问题。当我运行下面的代码片段,它报告错误:webapp2 http错误500
localhost is currently unable to handle this request.HTTP ERROR 500
import webapp2
import cgi
form="""
<!DOCTYPE html>
<html><head>
<title>Unit 2 Rot 13</title>
</head>
<body>
<h2>Enter some text to ROT13:</h2>
<form method="post">
<textarea name="text" style="height: 100px; width: 400px;">{{text}}</textarea>
<br>
<input type="submit" value="Submit Query">
</form>
</body></html>"""
class MainHandler(webapp2.RequestHandler):
def get(self):
self.response.out.write(form)
def post(self):
text = self.request.get('text')
self.response.out.write(self.request)
app = webapp2.WSGIApplication([
('/', MainHandler)], debug=True)
但是,当我在post
方法删除一行代码,它工作得很好。已删除的部分:text = self.request.get('text')
任何人都可以帮助我吗?
除了第一行(这会表现为不同的问题),我没有看到任何问题与您的代码,缩进错误并'paste.httpserver'运行时,它工作正常。你确定你发布了导致问题的相同代码吗? – mhawke
@mhawke是的,它是相同的代码。 paste.httpserver与Google App Engine类似吗? –
'paste.httpserver'允许您在应用引擎之外运行'webapp2'应用(https://webapp2.readthedocs.io/en/latest/tutorials/quickstart.nogae.html#quick-start-to -use-webapp2-应用程序引擎之外)您可以在应用程序引擎之外尝试您的代码。另外,请查看应用程序日志 - 500错误通常是您的代码中未处理的异常或运行应用程序失败的结果。 – mhawke