sqlite3.ProgrammingError: You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings

后端 未结 5 1339
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-02 10:44

Using SQLite3 in Python, I am trying to store a compressed version of a snippet of UTF-8 HTML code.

Code looks like this:

...
c = connection.cursor()         


        
5条回答
  •  孤街浪徒
    2020-12-02 11:44

    You could store the value using repr(html) instead of the raw output and then use eval(html) when retrieving the value for use.

    c.execute('insert or ignore into blah values (?, ?)',(1, repr(zlib.compress(html))))
    

提交回复
热议问题