Trying to store Utf-8 data in datastore getting UnicodeEncodeError

妖精的绣舞 提交于 2019-12-04 11:47:29

I use following helper in my projects

def force_utf8(string):
    if type(string) == str:
        return string
    return string.encode('utf-8')

Use it to escape all your unicode data before passing to GAE. Also you can find useful the following snippet:

def force_unicode(string):
    if type(string) == unicode:
        return string
    return string.decode('utf-8')
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!