InterfaceError: Error binding parameter 0 - probably unsupported type when runing my django script

InterfaceError: Error binding parameter 0 - probably unsupported type when runing my django script

我有以下功能

def get_id(entityName, text):  

"""Retrieve an entity's unique ID from the database, given its associated     text.
If the row is not already present, it is inserted.
The entity can either be a sentence or a word."""  

    tableName = entityName + 's'  
    columnName = entityName
    cursor.execute('SELECT rowid FROM ' + tableName + ' WHERE ' + columnName + ' = %s', (text,))
    row = cursor.fetchone()

    if row:
        return row[0]
    else:
        cursor.execute('INSERT INTO ' + tableName + ' (' + columnName + ') VALUES (?)', (text,))
        return cursor.lastrowid  

每当调用此方法时都会产生此错误

 cursor.execute('SELECT rowid FROM ' + tableName + ' WHERE ' + columnName + ' = ?', (text,))
InterfaceError: Error binding parameter 0 - probably unsupported type.

当前,当我在 django 中 运行 时,这个错误正在产生 否则它工作正常。 可能是什么原因?

这里我的参数 0(文本)的类型是 <type 'unicode'> ,数据库中的列数据类型是 text type 所以错误

InterfaceError: Error binding parameter 0 - probably unsupported type.

很明显,因为参数 0 不符合数据库列的类型
我没有早点得到这个,因为我是从另一个来源得到的。
但是在得到它不是文本类型之后我不得不将它转换为文本类型
str(text)
它现在工作得很好