Error Importing Excel Data into MySQL using Python

Viewed 43

I am trying to get data from an excel spreadsheet into a MySQL database using Python. I can do it fine if add my records to a list of tuples manually in my SQL query, but trying to loop through the records I get an error stating the tuple index out of range. Not sure what the issue is here and how to remedy it. Any help would be appreciated. Thank you.

Picture is attached for code and error messages. ErrorMSG PythonCode

import mysql.connector
import xlrd

mydb = mysql.connector.connect(
    host = "localhost",
    user = "root",
    passwd = "*******",
    database = "testdb",
)

mycursor = mydb.cursor()

loc=("E:\\SOX Reports\\2021 Reports\\populateData.xlsx")

l=list()
a=xlrd.open_workbook(loc)
sheet=a.sheet_by_index(0)
sheet.cell_value(0,0)

for i in range (1,418):
    l.append(tuple(sheet.row_values(i)))
addRows = "insert into emplist (ID,SITE, OU, firstName) values(%s,%s,%s,%s)"
mycursor.executemany(addRows,l)
mydb.commit()
mydb.close()
0 Answers
Related