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

  • SEARCH
  • Home
  • 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 7852777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:30:12+00:00 2026-06-02T19:30:12+00:00

please, can someone help me with the code bellow? When I run it the

  • 0

please, can someone help me with the code bellow?
When I run it the logs said:

return method(*args, **kwargs)
  File "C:\Users\CG\Documents\udacity\rot13serendipo\main.py", line 51, in post
    text = rot13(text)
  File "C:\Users\CG\Documents\udacity\rot13serendipo\main.py", line 43, in rot13
    return st.translate(tab)
TypeError: character mapping must return integer, None or unicode
   INFO     2012-04-28 20:02:26,862 dev_appserver.py:2891] "POST / HTTP/1.1" 500 -

I know the error must be in rot13(). But when I run this procedure in the IDE it works normally.

Here my code:

import webapp2

form= """
  <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;"></textarea>
      <br>
      <input type="submit">
    </form>
  </body>

  </html> """

def rot13(st):
    import string
    tab1 = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
    tab2 = 'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM'
    tab = string.maketrans(tab1, tab2)
    return st.translate(tab)

class MainHandler(webapp2.RequestHandler):
    def get(self):
        self.response.out.write(form)

    def post(self):
        text = self.request.get("text")
        text = rot13(text)
        self.response.out.write(text)


app = webapp2.WSGIApplication([('/', MainHandler)],
                          debug=True)

Thanks in advance for any help!

  • 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-02T19:30:13+00:00Added an answer on June 2, 2026 at 7:30 pm

    It’s probably because the text is being entered as unicode:

    >>> def rot13(st):
    ...     import string
    ...     tab1 = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
    ...     tab2 = 'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM'
    ...     tab = string.maketrans(tab1, tab2)
    ...     return st.translate(tab)
    ... 
    >>> rot13('test')
    'grfg'
    >>> rot13(u'test')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "<stdin>", line 6, in rot13
    TypeError: character mapping must return integer, None or unicode
    >>> 
    

    This question covers what you need:

    • How do I get str.translate to work with Unicode strings?

    If you are sure that unicode strings aren’t important I guess you could just:

    return str(st).translate(tab)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please can someone help? I have the following code which uploads a file to
can someone please help me. why does this return an error: Dim stuff As
Can someone please help? I use Google code’s Moq framework for mocking within my
Can someone help me with some PHP please. The original code ~works, but the
Im a beginner to css, please can someone help me get this element to
Can someone please help quickly mute or unmute the stage volume in Flash CS3
Can someone please help me with using Regex with NSPredicate? NSString *regex = @(?:[A-Za-z0-9]);
Can someone please help me out with a JavaScript/jQuery solution for this arithmetic problem:
Can someone please help me figure out a way to achieve the following (see
Can someone please help me to force my website to redirect to using www.

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.