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.

No comments: