Error while inserting data into mysql table using python from excel sheet -


here trying import data excel mysql table, getting error like: not arguments converted during string formatting

import xlrd import mysqldb,os,os.path,datetime dt os.chdir("file path") filename = raw_input("enter file name: ",) workbook = xlrd.open_workbook(filename) sheet = workbook.sheet_by_index(0) date = dt.datetime.today().strftime("%d/%m/%y") fname = filename user = 'umd' database = mysqldb.connect (host="localhost", user = "root", passwd = "psswd", db = "mrkt_data") cursor = database.cursor() r in range(0, sheet.nrows):     name      = sheet.cell(r,0).value     email_id      = sheet.cell(r,1).value     alt_numbr      = sheet.cell(r,2).value     dob      = sheet.cell(r,3).value     mobile      = sheet.cell(r,4).value     functional_area      = sheet.cell(r,5).value     specialization      = sheet.cell(r,6).value     industry      = sheet.cell(r,7).value     resume_title      = sheet.cell(r,8).value     keyskill      = sheet.cell(r,9).value     work_exp      = sheet.cell(r,10).value     curnt_emplyr      = sheet.cell(r,11).value     prev_emplyr      = sheet.cell(r,12).value     curnt_sal      = sheet.cell(r,13).value     level      = sheet.cell(r,14).value     curnt_loc      = sheet.cell(r,15).value     pref_loc      = sheet.cell(r,16).value     course_pri_high_edu      = sheet.cell(r,17).value     splztn_pri_high_edu      = sheet.cell(r,18).value     inst_pri_high_edu      = sheet.cell(r,19).value     course_sec_high_edu      = sheet.cell(r,20).value     splztn_sec_high_edu       = sheet.cell(r,21).value     inst_sec_high_edu       = sheet.cell(r,22).value     last      = sheet.cell(r,23).value     active      = sheet.cell(r,24).value     date      = sheet.cell(r,25).value     gender      = sheet.cell(r,26).value     age      = sheet.cell(r,27).value      address      = sheet.cell(r,28).value     resume_id      = sheet.cell(r,29).value      query =  insert data (name,email_id,alt_numbr,dob,mobile,functional_area,specialization,industry,resume_title,keyskill,work_exp,curnt_emplyr,prev_emplyr,curnt_sal,level,curnt_loc,pref_loc,course_pri_high_edu,splztn_pri_high_edu,inst_pri_high_edu,course_sec_high_edu,splztn_sec_high_edu,inst_sec_high_edu,last,active,date,gender,age,address,resume_id,market_type,date_logged,source) values ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s');"     values = (name,email_id,alt_numbr,dob,mobile,functional_area,specialization,industry,resume_title,keyskill,work_exp,curnt_emplyr,prev_emplyr,curnt_sal,level,curnt_loc,pref_loc,course_pri_high_edu,splztn_pri_high_edu,inst_pri_high_edu,course_sec_high_edu,splztn_sec_high_edu,inst_sec_high_edu,last,active,date,gender,age,address,resume_id,user,date,fname) cursor.execute(query, values) cursor.close() database.commit() database.close() print "no of rows : ", sheet.nrows print "" print " done! " print "" 


error:      traceback (most recent call last):      file "excel2mysql.py", line 60, in <module>      cursor.execute(query, values)      file "/usr/lib/python2.7/dist-packages/mysqldb/cursors.py", line 159, in execute      query = query % db.literal(args)      typeerror: not arguments converted during string formatting 

you have 33 items want insert, 32 places insert them. try below code. (i added %s)

 query =  insert data (name,email_id,alt_numbr,dob,mobile,functional_area,specialization,industry,resume_title,keyskill,work_exp,curnt_emplyr,prev_emplyr,curnt_sal,level,curnt_loc,pref_loc,course_pri_high_edu,splztn_pri_high_edu,inst_pri_high_edu,course_sec_high_edu,splztn_sec_high_edu,inst_sec_high_edu,last,active,date,gender,age,address,resume_id,market_type,date_logged,source) values ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s');" 

Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -