2016-07-06 178 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上運行它,它工作正常。 –