python - 接口(interface)错误: Error binding parameter 0 - probably unsupported type when runing my django script

标签 python django python-2.7 sqlite cursor

我有以下功能

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)
它现在就像一个魅力

关于python - 接口(interface)错误: Error binding parameter 0 - probably unsupported type when runing my django script,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49835272/

相关文章:

python - 为什么 ipywidget 按钮调用的 my 函数不返回输出?

python - 如何在Python中将文件从gml转换为edgelist?

Python ctypes : how to allocate output buffer for C function in callback

python - Django taggit 聚合查询返回每个标签的计数

django - 模型下一个可用的主键

django - 潜在的 docker 权限问题导致枕头说它没有安装,尽管它是

Python http服务器存储接收到的消息

python - python 中的 TimedRotatingFileHandler 的翻转没有发生

python - 带有是/否输入的 While 循环 (Python)

python - 您最非 Python 的代码片段