替换UTF-8特殊字符

时间:2020-01-15 11:02:23

标签: python-3.x unicode encoding utf-8

我有一个包含特殊字符的字符串: “Mystring?”

这是我的mysql数据库编码设置:

enter image description here

这是我得到的错误:

Incorrect string value: '\xF0\x9F\x9A\xB0' for column 'name' at row 1

为避免错误,我也尝试替换字符序列,但未成功:

>>>string = "Mystring?"
>>>print(string.encode())
b'Mystring\xf0\x9f\x9a\xb0'
>>>print(string.encode().replace("\xf0\x9f\x9a\xb0",""))
TypeError: a bytes-like object is required, not 'str'

0 个答案:

没有答案