1

在我的网站上使用 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']
4

1 回答 1

1

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

于 2013-01-30T07:43:30.897 回答