我正在使用Python中的SQLite3,尝试存储一个UTF-8 HTML代码片段的压缩版本。
代码如下:
...
c = connection.cursor()
c.execute('create table blah (cid integer primary key,html blob)')
...
c.execute('insert or ignore into blah values (?, ?)',(cid, zlib.compress(html)))
你在哪个步骤遇到了错误:
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.
如果我使用“text”而不是“blob”,并且不压缩HTML片段,那么一切都正常(尽管数据库太大)。当我使用“blob”并通过Python zlib库进行压缩时,就会出现上述错误消息。我查找了一下,但没有找到简单的答案。