Tuesday, December 31, 2013

Python: xlrd - bad magic number for file header

Problem:
Working in Pylons for a project, I built a tool to allow file uploads and one feature used xlrd to convert Excel files to CSV files. When I went to transform these files using xlrd, I got an error saying: bad magic number for file header.

Solution:
Turned out the file got corrupted as I uploaded it on Windows but did not use a binary flag when storing the file. Adding this flag fixed the issue and allowed xlrd to continue properly.

1 comment:

Sri said...

I've also got the same problem. Could you please share what the binary flag is and how to add it?