Python sqlite3.InterfaceError:错误绑定参数 1 - 可能不受支持的类型

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12952546/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 12:15:36  来源:igfitidea点击:

sqlite3.InterfaceError: Error binding parameter 1 - probably unsupported type

pythonsqlite

提问by Faris

I am having this annoying error that I could not solve.. here is my function

我遇到了无法解决的烦人错误..这是我的功能

def savePicture(pic):
try:
    connection=sqlite3.connect('/home/faris/Desktop/site/site.db')
    db=connection.cursor()
    print type(pic.user.profile_picture)
    db.execute('INSERT INTO pictures (picture_id, caption, created_time, picture_url, link, username,full_name,profile_picture) VALUES (?,?,?,?,?,?,?,?)',
        [
        pic.id,
        pic.caption,
        pic.created_time,
        pic.get_standard_resolution_url(),
        pic.link,
        pic.user.username,
        pic.user.full_name,
        pic.user.profile_picture
        ])
    connection.commit()
    connection.close()
except sqlite3.IntegrityError:
    print 'pic already exist'

And here is my Table (Sqlite :D )

这是我的表(Sqlite:D)

-- Describe PICTURES
CREATE TABLE "pictures" (
"picture_id" INTEGER PRIMARY KEY,
"caption" TEXT,
"created_time" TEXT,
"picture_url" TEXT,
"link" TEXT,
"username" TEXT,
"full_name" TEXT,
"profile_picture" TEXT
)

And this is the error I am having,

这是我遇到的错误,

<type 'str'>
Traceback (most recent call last):
File "/home/faris/Desktop/site/cron/pictures.py", line 15, in <module>
savePicture(picture)
File "/home/faris/Desktop/site/db.py", line 36, in savePicture
pic.user.profile_picture
sqlite3.InterfaceError: Error binding parameter 1 - probably unsupported type.

As you see I have printed the type of the "pic.user.profile_picture" and it returned str I have also tried using these two functions ( unicode and str ) just to make sure that it is returning a string with no luck..

正如你所看到的,我已经打印了“pic.user.profile_picture”的类型,它返回了 str 我也尝试过使用这两个函数( unicode 和 str )只是为了确保它返回一个没有运气的字符串..

Any ideas? cheers :D

有任何想法吗?欢呼:D

采纳答案by Faris

Ok, That is stupid lol

好吧,那是愚蠢的哈哈

    pic.caption,
    pic.created_time,

are not TEXT type..but the error msg is saying the problem from pic.user.profile_picture. thus, if you have this error just check all the parameters:)

不是文本类型..但错误消息是说来自 pic.user.profile_picture 的问题。因此,如果您遇到此错误,只需检查所有参数:)

Read the comment below :)

阅读下面的评论:)