在Python中存储唯一字符

时间:2013-01-30 06:20:05

标签: php python mysql facebook

在我的网站上使用Facebook登录时,新用户的所有喜欢都存储在数据库中。但是,虽然存储唯一字符(来自其他语言和所有字符的字符)没有存储,但我收到如下错误:

Warning at /facebook/connect/

**Incorrect string value: '\xE2\x99\xA5 Lo...' for column 'name' at row 1**

Request Method:     POST
Request URL:    http://pydev.aviesta.com/facebook/connect/?facebook_login=1
Django Version:     1.4.2
Exception Type:     Warning
Exception Value:    

Incorrect string value: '\xE2\x99\xA5 Lo...' for column 'name' at row 1

Exception Location:     /usr/lib64/python2.6/site-packages/MySQLdb/cursors.py in _warning_check, line 89
Python Executable:  /usr/bin/python
Python Version:     2.6.6
Python Path:    

['/mnt/aviesta/pythondev/mezzanine_aviesta',
 '/usr/lib/python2.6',
 '/usr/lib/python2.6/site-packages/satchless-2011.9.pre-py2.6.egg',
 '/usr/lib/python2.6/site-packages/django_mptt-0.5.4-py2.6.egg',
 '/usr/lib/python2.6/site-packages/django_sorting-0.1-py2.6.egg',
 '/usr/lib/python2.6/site-packages/python_memcached-1.48-py2.6.egg',
 '/usr/lib/python2.6/site-packages/sorl_thumbnail-11.12-py2.6.egg',
 '/usr/lib/python2.6/site-packages/django_treebeard-1.61-py2.6.egg',
 '/usr/lib/python2.6/site-packages/django_haystack-2.0.0_beta-py2.6.egg',
 '/usr/lib/python2.6/site-packages/django_extra_views-0.2.0-py2.6.egg',
 '/usr/lib/python2.6/site-packages/South-0.7.3-py2.6.egg',
 '/usr/lib/python2.6/site-packages/PIL-1.1.7-py2.6-linux-x86_64.egg',
 '/mnt/software/django-oscar',
 '/usr/lib/python2.6/site-packages/django_extensions-0.9.1-py2.6.egg',
 '/usr/lib/python2.6/site-packages/pip-1.0-py2.6.egg',
 '/usr/lib/python2.6/site-packages/django_facebook-4.0.8-py2.6.egg',
 '/usr/lib/python2.6/site-packages/django_socialregistration-0.5.8-py2.6.egg',
 '/usr/lib/python2.6/site-packages/mock-1.0.1-py2.6.egg',
 '/usr/lib64/python26.zip',
 '/usr/lib64/python2.6',
 '/usr/lib64/python2.6/plat-linux2',
 '/usr/lib64/python2.6/lib-tk',
 '/usr/lib64/python2.6/lib-old',
 '/usr/lib64/python2.6/lib-dynload',
 '/usr/lib64/python2.6/site-packages',
 '/usr/lib64/python2.6/site-packages/PIL',
 '/usr/lib/python2.6/site-packages',
 '/usr/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg-info',
 '/mnt/aviesta/pythondev/mezzanine_aviesta/webdev']

1 个答案:

答案 0 :(得分:1)

对于非ascii字符,最好使用utf-8作为默认字符集。因此,您应该确保您的数据库或表是使用utf-8编码字符串。如果你正在使用Django,它已经处理utf-8的东西是默认的。您应该关注的唯一事情是第三方服务的响应输出,可能不会以utf-8编码。