Skip to content

mimetypes module does not recognize jp2 type #85957

Closed

Description

@naro
mannequin
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

Activity

  1. naro commented on Sep 15, 2020

    naromannequin
    MannequinAuthor

    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'

  2. added
    type-bugAn unexpected behavior, bug, or error
    on Sep 15, 2020
  3. andresdelfino commented on Sep 17, 2020

    @andresdelfino
    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? :)

  4. naro commented on Sep 18, 2020

    naromannequin
    MannequinAuthor

    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

  5. andresdelfino commented on Sep 18, 2020

    @andresdelfino
    Contributor

    Nice debugging!

  6. iritkatriel commented on Jan 18, 2022

    @iritkatriel
    Member

    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.

  7. added
    3.11only security fixes
    type-featureA feature request or enhancement
    and removed
    type-bugAn unexpected behavior, bug, or error
    on Jan 18, 2022
  8. 2 remaining items

  9. transferred this issue fromon Apr 10, 2022
  10. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Nov 23, 2023
  11. hugovk commented on Nov 18, 2024

    @hugovk
    Member

    Please see PR #126966.

  12. added
    3.14bugs and security fixes
    and removed
    3.11only security fixes
    3.14bugs and security fixes
    on Nov 18, 2024
  13. added a commit that references this issue on Nov 18, 2024
  14. added a commit that references this issue on Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions