私は現在、自分の目的のためにsqliteデータベースにファイル名を保持しています。特殊文字(éなど)を含むファイルを挿入しようとすると、次のエラーがスローされます。
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.
pysqliteに送信された値を次のようなUnicodeメソッドでラップして、「アプリケーションをUnicode文字列に切り替える」と、次の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")])
ここでの私のコードはどのように見えるべきですか?