Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8088509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:06:39+00:00 2026-06-05T19:06:39+00:00

the cgi.escape section (below) throws traceback in dev server, but when I comment out

  • 0

the cgi.escape section (below) throws traceback in dev server, but when I comment out cgi.escape, I get syntax error on RequestHandler. I’m following Google’s tutorial, which includes 2 submit buttons for 1 form, which is unclear to me, as is the /sign? form action; my form below is 1 (not 2) submit button, for combined text and radio field form, so I’m unsure if I’m doing the last section properly or even the form. I’ve got all the imports for this to work. Got to get these user form values in Datastore, spreadsheets, or something, anything…help is greatly appreciated.

Traceback (most recent call last):   Fil "/home/paul/Desktop/google_appengine/google/appengine/ext/webapp/_webapp25.py", line 701, in __call__
    handler.get(*groups)   File "/home/paul/Desktop/emot/index.py", line 39, in get
    cgi.escape(name))) TypeError: not all arguments converted during string formatting

Code:

    name=self.request.get("name")
        self.response.out.write("""
        <form action="/sign?/s" method="post">
            <p>First Name: <input type="text" name="name"/></p>
            <p><input type="radio" name="mood" value="good">Good</p>
            <p><input type="radio" name="mood" value="bad">Bad</p>
            <p><input type="radio" name="mood" value="fair">Fair</p>
            <p><input type="submit"value="Process"></p>
        </form>
    </body>
</html>""" % (urllib.urlencode({"name": name}), 
                    cgi.escape(name)))       # < < < no string convert HERE 

class Info(webapp.RequestHandler):     # < < Syntax Error when ^ ^ is commented out.
    def post(self):
        name = self.request.get("name")
        visitor = Visitor(parent=info_key(name))
        visitor.content = self.request.get("mood")
        visitor.put()
        self.redirect("/?" + urllib.urlencode({"name": name}))

application = webapp.WSGIApplication([
    ("/", MainPage),            # < < v v Unsure about these...2 submits?
    ("/sign", Info)
], debug=True)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T19:06:41+00:00Added an answer on June 5, 2026 at 7:06 pm

    This is where you’re running into the problem. Note that this entire chunk of code is wrapped in a function call:

    self.response.out.write("""
        <form action="/sign?/s" method="post">
            <p>First Name: <input type="text" name="name"/></p>
            <p><input type="radio" name="mood" value="good">Good</p>
            <p><input type="radio" name="mood" value="bad">Bad</p>
            <p><input type="radio" name="mood" value="fair">Fair</p>
            <p><input type="submit"value="Process"></p>
        </form>
    </body>
    </html>""" % (urllib.urlencode({"name": name}), 
                    cgi.escape(name))) # self.response.out.write ends here
    

    Let’s take out the function call for now, as that’s not really the issue here. Note that I’ll also remove the extra trailing bracket that would finish the function call. This is the reason you were getting a syntax error when you commented out that last line – you were also commenting out the close bracket for the function call, and the interpreter won’t allow the defining of new classes until it’s complete.

    That leaves us with this:

    """
    <form action="/sign?/s" method="post">
            <p>First Name: <input type="text" name="name"/></p>
            <p><input type="radio" name="mood" value="good">Good</p>
            <p><input type="radio" name="mood" value="bad">Bad</p>
            <p><input type="radio" name="mood" value="fair">Fair</p>
            <p><input type="submit"value="Process"></p>
        </form>
    </body>
    </html>""" % (urllib.urlencode({"name": name}), 
                    cgi.escape(name)) # one less bracket!
    

    What we’re left with is a string formatting operation, of the format """string literal""" % (tuple, of, values). For this operation to work, you need to include specifiers (I find ‘hooks’ a slightly more descriptive term) for each of the values you’d like to include in the string. These will always start with a percent sign, and have one or more characters following. You can read more about it at the Python Docs, but a few quick examples include %d for an integer, %s for a string, and %f for a float value.

    Your code example has two arguments for this operation, urllib.urlencode({"name": name}), and cgi.escape(name). However, your string doesn’t contain any specifiers (%s, etc) for the interpreter to understand where you’d like to put them.

    As I see it, you have two choices – you can either remove the arguments all together (but make sure you leave a trailing bracket for the self.response.out.write call!), or put in the hooks where you need them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There is cgi.escape but that appears to be implemented in pure python. It seems
cgi.escape seems like one possible choice. Does it work well? Is there something that
Looking at some examples, I came across lines like: output.safe_concat(<input type=\hidden\ id=\#{k}\ name=\#{CGI.escape(k)}\ value=\#{CGI.escape(v)}\/>)
using Fast CGI I can't get it to read the php.ini file. See my
What's the difference between URI.escape and CGI.escape and which one should I use?
Here is what I have- A CGI script on server A gets the parameters
I am using the CGI escape method to escape the url for the href
CGI.escapeHTML is pretty bad, but CGI.unescapeHTML is completely borked. For example: require 'cgi' CGI.unescapeHTML('&#8230;')
Hello guys i have a little problem i get an error: File C:\Users\kokki\Desktop\gb1\main.py, line
I have CGI proxy that works on my localhost, but when I try to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.