I have a routine where I have to read from a Excel which has a column with links to get individual .xlsx/.xls files that people upload into the form containing some information.
My problem is, people do not always upload the correct file format. So I had to create exceptions to handle that. I save the links that have a exception in a list, but I don't know which exception blocked it. Here's my code:
erros = []
for i in links:
try:
name = i[50:]
df = pd.read_excel(i, header = 1, usecols = col_names, encoding = 'utf-8') #usecols = names)
file_name = r"%s\%s" %(pasta_sol,name)
writer = pd.ExcelWriter(file_name , engine='xlsxwriter')
df.to_excel(writer, header = True, index = True)
writer.close()
except (TypeError, IndexError, ValueError, XLRDError, BadZipFile, urllib.error.URLError) as e:
erros.append(i)
There is a way to append to each file that has a exception which one was it? It could be a list or a new df that looks like it:
erros = [['http://abs.company.pdf', 'TypeError'],['http://abs.company.xls','XLRDError']]
or df.
*There are thousands of files to read per day.
Thanks