Php 在Python中存储唯一字符
在我的网站上使用Facebook登录时,新用户的所有喜好都存储在数据库中。但是,在存储唯一字符(来自其他语言的字符和所有字符)时,不会存储这些字符,我会遇到如下错误:Php 在Python中存储唯一字符,php,python,mysql,facebook,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.avie
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']
对于非ascii字符,最好使用utf-8作为默认字符集。所以您应该确保您的数据库或表使用utf-8编码字符串。如果您使用的是Django,那么默认情况下它已经可以处理utf-8了。您唯一应该关心的是第三方服务响应的输出,它可能不会用utf-8编码。对于非ascii字符,最好使用utf-8作为默认字符集。所以您应该确保您的数据库或表使用utf-8编码字符串。如果您使用的是Django,那么默认情况下它已经可以处理utf-8了。您唯一应该关心的是第三方服务响应的输出,它可能没有用utf-8编码。我认为您需要在查询中添加一些转义序列,无论如何,如果您发布代码会更好。我认为您需要在查询中添加一些转义序列,不管怎样,如果你发布你的代码会更好。我已经在我的数据库中应用了这些东西。但它仍然给出了同样的错误。不知道那里到底发生了什么@RanbirSingh我尝试在pythonshell中打印'\xE2\x99\xA5',它给出了一个♥ 角色,我不确定这是否是正确的角色。分配给Django models.CharField是有效的。所以也许你可以在这里放更多的相关代码。是的,我想这是一个没有保存的字符。你能把它分配到Django shell中的名称文件中,然后保存而不出错吗?我已经为我的DB应用了这些东西。但它仍然给出了同样的错误。不知道那里到底发生了什么@RanbirSingh我尝试在pythonshell中打印'\xE2\x99\xA5',它给出了一个♥ 角色,我不确定这是否是正确的角色。分配给Django models.CharField是有效的。所以也许你可以在这里放更多的相关代码。是的,我想这是一个没有保存的字符。你能把它分配到Django shell中的名称文件中并保存而不出错吗?