openpyxl creates broken files if mimetypes.init() is called after openpyxl has been imported
Created originally on Bitbucket by Hans-Jakob (Hans-Jakob Holtz)
Whenever mimetypes.init()
gets called after openpyxl
has been imported, all subsequent save
(or save_workbook
, save_virtual_workbook
etc) calls result in a broken file.
Code to reproduce:
#!python
from openpyxl import Workbook
import mimetypes
if __name__ == '__main__':
Workbook().save('good.xlsx')
mimetypes.init()
Workbook().save('bad.xlsx')
The same symptom (broken xlsx file with invalid entry '<Default ContentType="text/xml" Extension="xml"/>'
in [Content_Types].xml) has already been described in #1077 (closed), but there it has been shrugged off as due to broken/weird mime-types configuration. Since calling mimetypes.init()
later is explicitly allowed and sufficient to reproduce the problem, I consider this a valid bug.
As a fix, I propose using a private mime database in manifest.py
to be independent from the global mime database (which possibly contains incompatible extension-to-type mappings).
I shall try to implement this proposed fix and send a pull request as soon as I have a working solution.