Title: mimetypes module does not recognize jp2 type
Type: behavior Stage:
Components: Versions: Python 3.8
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: adelfino, naro
Priority: normal Keywords:

Created on 2020-09-15 04:31 by naro, last changed 2020-09-18 12:27 by adelfino.

Messages (4)
msg376927 - (view) Author: Radim Novotny (naro) Date: 2020-09-15 04:31
Even if jp2 is in the official list of types it's not recognized by the MimeTypes.guess_type:

   >>> from mimetypes import MimeTypes
   >>> MimeTypes().guess_type('test.jp2')
   (None, None)

The same example works in Python 3.7 and returns 'image/jp2'
msg377074 - (view) Author: Andrés Delfino (adelfino) * (Python triager) Date: 2020-09-17 23:25
Hi, Radim!

I've tested with 3.7.8 and got (None, None). I'm curious on how you got that 'image/jp2' output.

It seems jp2 was never supported by looking into the git history of Lib/

Would you like to open a PR to support it? :)
msg377086 - (view) Author: Radim Novotny (naro) Date: 2020-09-18 05:41
Hi Andrés,

tried again and the difference is between 3.7.4 and 3.7.5
The jp2 mimetype is read from /etc/apache2/mime.types (see knownfiles in so the mime type does not have to be in the hardcoded, but in version 3.7.5 it stopped working. 

I think it's because of using _types_map_default instead of types_map in some places.

Since jp2 is an official mime type it should be added to the list but I also think we should try to identify the issue with _types_map_default.

Seems to be related to

I will have look if I can find out what was changed and why.

msg377113 - (view) Author: Andrés Delfino (adelfino) * (Python triager) Date: 2020-09-18 12:27
Nice debugging!
Date User Action Args
2020-09-18 12:27:11adelfinosetmessages: + msg377113
2020-09-18 05:41:01narosetmessages: + msg377086
2020-09-17 23:25:35adelfinosetnosy: + adelfino
messages: + msg377074
2020-09-15 04:31:47narocreate