2016-07-06 179 views
2

我尝试在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') 任何人都可以帮助我吗?

+0

除了第一行(这会表现为不同的问题),我没有看到任何问题与您的代码,缩进错误并'paste.httpserver'运行时,它工作正常。你确定你发布了导致问题的相同代码吗? – mhawke

+0

@mhawke是的,它是相同的代码。 paste.httpserver与Google App Engine类似吗? –

+1

'paste.httpserver'允许您在应用引擎之外运行'webapp2'应用(https://webapp2.readthedocs.io/en/latest/tutorials/quickstart.nogae.html#quick-start-to -use-webapp2-应用程序引擎之外)您可以在应用程序引擎之外尝试您的代码。另外,请查看应用程序日志 - 500错误通常是您的代码中未处理的异常或运行应用程序失败的结果。 – mhawke

回答

1

首先从第一行删除空格。

然后显示您从用户处获得的“文本”。

text = self.request.get('text') 
self.response.out.write(text) 
+0

我试过了,但还是失败了...还有其他想法吗? –

+1

我在本地GAE上运行它,它工作正常。 –