小编Kin*_*nka的帖子

通过向mysql插入4字节unicode引发警告

请看以下内容:

/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']))
Run Code Online (Sandbox Code Playgroud)

字符串'\xF0\x9F\x91\x8A,实际上是一个4字节的unicode : u'\U0001f62a'. mysql的字符集是utf-8但是插入4字节的unicode会截断插入的字符串.我搜索了这个问题,发现5.5.3下的mysql不支持4字节unicode,不幸的是我的是5.5.224.我不想升级mysql服务器,所以我只想过滤python中的4字节unicode,我尝试使用正则表达式但失败了.那么,有什么帮助吗?

python regex mysql astral-plane

7
推荐指数
1
解决办法
3568
查看次数

标签 统计

astral-plane ×1

mysql ×1

python ×1

regex ×1