sqlite3对raspbian和manjaro的区别?

时间:2017-09-19 03:42:54

标签: python sqlite

我在笔记本电脑上编写了一个脚本,该脚本正在运行Manjaro,它使用CSV文件中的值填充数据库。它在我的笔记本电脑上运行正常,但是当我在我的Raspberry Pi 3上运行脚本(运行raspbian stretch)时,它将无法运行,在以下行给出错误:

cursor.execute('''SELECT simplified FROM dictionary WHERE (traditional = ? OR simplified = ?)''', (char, char))

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.

上面的两个char变量是中文字符。为什么它在一个系统上工作而在另一个系统上不工作?

是否与软件包版本有关?在Manjaro上,我有sqlite3版本3.20.1,Raspbian运行3.16.2(虽然我尝试在Raspbian上卸载sqlite3包并运行脚本,但似乎没有区别,它仍然试图运行,所以也许是sqlite3库是主库的一部分吗?)

我该如何解决这个问题?我已经在文件顶部指定了utf-8编码

修改

这里有更多代码。传入的游标是一个sqlite3.Cursor对象

def convertToSimplified(sentence, cursor):
    s = ""
    sentence = sentence.replace('\n', '')
    for char in sentence:
        cursor.execute('''SELECT simplified FROM dictionary WHERE (traditional = ? OR simplified = ?)''', (char, char))
        result = cursor.fetchone()
        if result is not None:
            s += result[0]
        else:
            s += char

    print(s)
    return s

0 个答案:

没有答案