我目前在一個sqlite數據庫中爲我自己的目的持久化文件名。每當我嘗試插入具有特殊字符(如電子等)的文件,它引發以下錯誤:pysqlite2:ProgrammingError - 你不能使用8位字節
pysqlite2.dbapi2.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字符串」與像unicode的方法pysqlite:unicode(filename)
,它拋出這個錯誤:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 66: ordinal not in range(128)
有什麼我可以做,以擺脫這種?修改我的所有文件以符合不是一個選項。
UPDATE 如果我通過filename.decode("utf-8")
解碼文本,我仍然得到上面的ProgrammingError。
我的實際代碼如下所示:
cursor.execute("select * from musiclibrary where absolutepath = ?;",
[filename.decode("utf-8")])
我應該在這裏我的代碼樣子的?
看起來像這樣的代碼,在你更新問題之後,實際上並不是產生錯誤的代碼,對吧? – metamatt 2011-01-11 05:23:48
對,後來在應用程序中使用了類似的代碼。 – 2011-01-12 16:13:38