Passing InMemoryUploadedFile which cannot be decompressed raises AttributeError

Issue #415 resolved
Kimmo Ahola
created an issue

InMemoryUploadedFile (file-like) objects are passed by Django. Openpyxl works great when load_workbook is passed an excel file (InMemoryUploadedFile). Also works for any other file that can be zip-decompressed (raises InvalidFileException). But passing a txt file (again InMemoryUploadedFile) from Django file upload to load_workbook raises an AttributeError.

Should any invalid file raise InvalidFileException?

File "/Users/kimmo/.virtualenvs/silverbucket/lib/python2.7/site-packages/openpyxl/reader/excel.py" in load_workbook
  119.         file_format = os.path.splitext(filename)[-1]
File "/Users/kimmo/.virtualenvs/silverbucket/bin/../lib/python2.7/posixpath.py" in splitext
  105.     return genericpath._splitext(p, sep, altsep, extsep)
File "/Users/kimmo/.virtualenvs/silverbucket/bin/../lib/python2.7/genericpath.py" in _splitext
  91.     sepIndex = p.rfind(sep)
Exception Value: 'InMemoryUploadedFile' object has no attribute 'rfind'

Using 2.1.4

Comments (5)

  1. CharlieC

    The exception handling in the reader is indeed misleading as most exceptions are reported as InvalidFileException. This will change if we ever get round to refactoring this particular piece of spaghetti but I can't see what that has to do with passing a txt file. That just won't work.

  2. Log in to comment