Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mimetypes module does not recognize jp2 type #85957

Closed
naro mannequin opened this issue Sep 15, 2020 · 6 comments · Fixed by #126966
Closed

mimetypes module does not recognize jp2 type #85957

naro mannequin opened this issue Sep 15, 2020 · 6 comments · Fixed by #126966
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@naro
Copy link
Mannequin

naro mannequin commented Sep 15, 2020

BPO 41791
Nosy @naro, @iritkatriel

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2020-09-15.04:31:47.953>
labels = ['type-feature', '3.11']
title = 'mimetypes module does not recognize jp2 type'
updated_at = <Date 2022-01-19.00:38:51.433>
user = 'https://github.com/naro'

bugs.python.org fields:

activity = <Date 2022-01-19.00:38:51.433>
actor = 'adelfino'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = []
creation = <Date 2020-09-15.04:31:47.953>
creator = 'naro'
dependencies = []
files = []
hgrepos = []
issue_num = 41791
keywords = []
message_count = 5.0
messages = ['376927', '377074', '377086', '377113', '410860']
nosy_count = 2.0
nosy_names = ['naro', 'iritkatriel']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue41791'
versions = ['Python 3.11']

Linked PRs

@naro
Copy link
Mannequin Author

naro mannequin commented Sep 15, 2020

Even if jp2 is in the official list of types https://www.iana.org/assignments/media-types/media-types.xhtml 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'

@naro naro mannequin added type-bug An unexpected behavior, bug, or error 3.8 (EOL) end of life labels Sep 15, 2020
@andresdelfino
Copy link
Contributor

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/mimetypes.py.

Would you like to open a PR to support it? :)

@naro
Copy link
Mannequin Author

naro mannequin commented Sep 18, 2020

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 mimetypes.py) so the mime type does not have to be in the mimetypes.py 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 https://bugs.python.org/issue4963

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

Cheers,
Radim

@andresdelfino
Copy link
Contributor

Nice debugging!

@iritkatriel
Copy link
Member

iritkatriel commented Jan 18, 2022

It is found by the module-level guess_type but not by the MimeType class's guess_type:

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

That difference is the subject of bpo-38656.

What remains to decide here is whether jp2 should be added to the builtin list of mimetypes.

@iritkatriel iritkatriel added 3.11 only security fixes type-feature A feature request or enhancement and removed 3.8 (EOL) end of life type-bug An unexpected behavior, bug, or error labels Jan 18, 2022
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
@iritkatriel iritkatriel added the stdlib Python modules in the Lib dir label Nov 23, 2023
josselinbuils pushed a commit to kili-technology/kili-python-sdk that referenced this issue Jan 8, 2024
mimetypes module does not find jp2 mime type on Windows.

See python/cpython#85957
josselinbuils pushed a commit to kili-technology/kili-python-sdk that referenced this issue Jan 8, 2024
mimetypes module does not find jp2 mime type on Windows.

See python/cpython#85957
josselinbuils pushed a commit to kili-technology/kili-python-sdk that referenced this issue Jan 8, 2024
mimetypes module does not find jp2 mime type on Windows.

See python/cpython#85957
josselinbuils pushed a commit to kili-technology/kili-python-sdk that referenced this issue Jan 8, 2024
mimetypes module does not find jp2 mime type on Windows.

See python/cpython#85957
josselinbuils pushed a commit to kili-technology/kili-python-sdk that referenced this issue Jan 8, 2024
mimetypes module does not find jp2 mime type on Windows.

See python/cpython#85957
josselinbuils pushed a commit to kili-technology/kili-python-sdk that referenced this issue Jan 8, 2024
mimetypes module does not find jp2 mime type on Windows.

See python/cpython#85957
@hugovk
Copy link
Member

hugovk commented Nov 18, 2024

Please see PR #126966.

@hugovk hugovk added 3.14 new features, bugs and security fixes and removed 3.11 only security fixes 3.14 new features, bugs and security fixes labels Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants