While importing data from csv, I realized that this error is triggered if the first row is not the header
list indices must be integers or slices, not str
first_name,last_name,email,password,role
Noak,Larrett,nlarrett0@ezinearticles.com,8sh15apPjI,Student
Duffie,Milesap,dmilesap1@wikipedia.org,bKNIlIWVfNw,Student
It only works if the first row is the header
first_name,last_name,email,password,role
Noak,Larrett,nlarrett0@ezinearticles.com,8sh15apPjI,Student
Duffie,Milesap,dmilesap1@wikipedia.org,bKNIlIWVfNw,Student
...
I tried overwriting before_import to remove any blank row
def before_import(self, dataset, using_transactions, dry_run, **kwargs):
indexes = []
for i in range(0, len(dataset)):
row = ''.join(dataset[i])
if row.strip() == '':
indexes.append(i)
for index in sorted(indexes, reverse=True):
del dataset[index]
return dataset
This works for all the rows, except the first row which should always contain the header, and if not the error is thrown.