Python将UTF8字符串插入sqlite

问题描述 投票:0回答:2

我知道有类似的问题,但是答案是独特的和令人困惑的。 我有这个字符串:

titulo = "Así Habló Zaratustra (Cómic)"

当我尝试将其插入SQLite数据库时,我会收到错误:

sqlite3.ProgrammingError: You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings (like text_factory = str). It is highly recommended that you instead just switch your application to Unicode strings.

我尝试了几件事而没有成功。请帮助
	

要告诉您要做的事情并使用

unicode
python sqlite encoding utf-8
2个回答
8
投票

titulo_unicode = titulo.decode('utf8')

库库将在插入时正确编码此问题,在选择时再次解码。
    

ExistediferençaEntrefiturizar executeScript E执行:

输入图像描述在这里


    


0
投票
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.