【发布时间】:2012-06-03 15:28:13
【问题描述】:
看下面:
/home/kinka/workspace/py/tutorial/tutorial/pipelines.py:33: Warning: Incorrect string
value: '\xF0\x9F\x91\x8A\xF0\x9F...' for column 't_content' at row 1
n = self.cursor.execute(self.sql, (item['topic'], item['url'], item['content']))
字符串'\xF0\x9F\x91\x8A,实际上是一个4字节的unicode:u'\U0001f62a'。 mysql 的字符集是 utf-8,但插入 4 字节 unicode 会截断插入的字符串。
我google了一下这样的问题,发现5.5.3下的mysql不支持4字节unicode,可惜我的是5.5.224。
我不想升级mysql服务器,所以我只想在python中过滤4字节的unicode,我尝试使用正则表达式但失败了。
那么,有什么帮助吗?
【问题讨论】:
-
那是 FISTED HAND SIGN 彩色表情符号:
????... -
@MartijnPieters -
unicodedata.name("\U0001f62a")说'SLEEPY FACE'(在 utf-8 中是b'\xf0\x9f\x98\xaa'),所以这里有些东西不合适...... -
其实就是一张睡眼惺忪的脸。我正在从
sina weibo(中国的推特)刮网页,我刮了这样的SLEEP FACE。 -
是的,
'\xF0\x9F\x91\x8A'.decode('utf8')是u'\U0001f44a',也就是'FISTED HAND SIGN':-)
标签: python mysql regex astral-plane