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

跟風遠走 提交于 2019-11-29 12:02:50
David Underhill

Try reading a little about how unicode works in Python:

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

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.

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

Try with encode

t ='việt ứng '
m = MyModel()
m.data = t.encode('utf-8')
m.put() #success!
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!