How to receive variables in a post in google app engine that contains string with chars like: õ á?

后端 未结 4 1552
悲&欢浪女
悲&欢浪女 2020-12-20 03:48
email = self.request.get(\'email\')
name = self.request.get(\'name\')
mail.send_mail(sender=\"myemail\", email=email, body=name, subject=\"sss \" + name + \"sdafsaã\         


        
相关标签:
4条回答
  • 2020-12-20 04:25

    You should use:

    email = self.request.get('email')
    name = self.request.get('name')
    mail.send_mail(sender="myemail", 
                   email=email, 
                   body=name, 
                   subject="hello " + name.encode('utf-8') + " user!")
    

    The variable name is a unicode string and should encoded in utf-8 or in the kind of encode you are using in you web application before concatenating to other byte strings.
    Without name.encode(), Python uses the default 7 bits ascii codec that can't encode that specific character.

    0 讨论(0)
  • 2020-12-20 04:28

    the problem is joining 2 strings: ||| body = name + "ã" => error ||| body = name + u"ã" => works!!! |||

    0 讨论(0)
  • 2020-12-20 04:30

    Try reading a little about how unicode works in Python:

    • Dive Into Python - Unicode
    • Unicode In Python, Completely Demystified

    Also, make sure you're running Python 2.5 if you are seeing this error on the development server.

    0 讨论(0)
  • 2020-12-20 04:34

    Try with encode

    t ='việt ứng '
    m = MyModel()
    m.data = t.encode('utf-8')
    m.put() #success!
    
    0 讨论(0)
提交回复
热议问题