Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.2k views
in Technique[技术] by (71.8m points)

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

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 )

-- 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..

Any ideas? cheers :D

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 :)

Read the comment below :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...