18
votes

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

2

2 Answers

18
votes

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

3
votes

The easiest way to solve that issue is- convert all the dataframe columns into str, and apply to_sql method. df = df.applymap(str) otherwise, you can change the data types of each column that are compatible with SQLite datatypes before saving the dataframe into SQLite table. dtype parameter of to_sql method would be useful to convert the datatypes of the columns while inserting the data into SQL table.