Python应用程序说无效语法?

时间:2014-04-19 04:49:26

标签: python

我一直在我的应用上获得无效语法,无法弄清楚原因。我在底部添加了追溯。我搜索了我的代码,没有任何缩进问题。不知道它可能是什么。

import webapp2
import cgitb
import string
import cgi

cgitb.enable()

alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
encrypted_alphabet = "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm"
new_string = ""

# this function will use ROT13 to transform a string
def rot13(textbox_input):
    global new_string
    global alphabet
    global encrypted_alphabet

    new_string=""

    for char in textbox_input:
        if char in alphabet:
            new_string = new_string + encrypted_alphabet[alphabet.find(char)]
        else:
            new_string = new_string + char
    return new_string

form="""
<form method = "post">

<center>
<h1>Schachte's ROT13 Encryptor</h1>
<textarea style="width:320px; height:115px;">%(text)s</textarea>
<br>
<br>
<input type="submit" value="Encrypt">

</form>
"""

class MainPage(webapp2.RequestHandler):

    def write_form(self, text=""):
        self.response.out.write(form % {"text"}

    def get(self):
        self.write_form()

    def post(self):
        global new_string
        text = rot13(str(self.request.get("text")))
        text = cgi.escape(new_string) #prevent users from submitting HTML
        self.write_form(text)

application = webapp2.WSGIApplication([
('/', MainPage),
], debug=True)

这是我的追溯:


Traceback (most recent call last):
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 239, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 298, in _LoadHandler
    handler, path, err = LoadObject(self._handler)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 84, in LoadObject
    obj = __import__(path[0])
  File "/Users/rschacht/Desktop/webdev/helloworld.py", line 45
    def get(self):
      ^
SyntaxError: invalid syntax

1 个答案:

答案 0 :(得分:4)

第43行

你忘了用另一个括号

关闭写功能