Skip to content

Extension for MIME type is not recognized #111637

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

Closed
frankenstein91 opened this issue Nov 2, 2023 · 8 comments
Closed

Extension for MIME type is not recognized #111637

frankenstein91 opened this issue Nov 2, 2023 · 8 comments
Labels
docs Documentation in the Doc dir easy stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@frankenstein91
Copy link

frankenstein91 commented Nov 2, 2023

Bug report

Bug description:

I currently have a problem with guessing file extensions from the MIME
type, unfortunately. I understood that only files with a registry at
IANA can be guessed and checked the linked page. As I understand, my
affected data is registered with IANA.

The IANA link:
https://www.iana.org/assignments/media-types/application/vnd.openxmlformats-officedocument.wordprocessingml.document

Python 3.11.5 (main, Sep  2 2023, 14:16:33) [GCC 13.2.1 20230801] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mimetypes
>>> print(mimetypes.guess_extension("vnd.openxmlformats-officedocument.wordprocessingml.document"))
None

I hoped to see .docx as a return value

CPython versions tested on:

3.11

Operating systems tested on:

Linux, Windows

Linked PRs

@frankenstein91 frankenstein91 added the type-bug An unexpected behavior, bug, or error label Nov 2, 2023
@zooba
Copy link
Member

zooba commented Nov 3, 2023

The type is application/vnd.openxmlformats-officedocument.wordprocessingml.document (note the "application" at the start). Both the media type and the subtype are required.

@frankenstein91
Copy link
Author

frankenstein91 commented Nov 3, 2023

Yes, I must have made a mistake when I copied the MIME type on my Linux system. But I still can't get any further on my Windows system.
@zooba: Do you see my mistake here too? Would be very nice

Python 3.11.6 (tags/v3.11.6:8b6ee5b, Oct  2 2023, 14:57:12) [MSC v.1935 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import mimetypes
>>> print(mimetypes.guess_extension("application/vnd.openxmlformats-officedocument.wordprocessingml.document"))
None
>>>

@zooba
Copy link
Member

zooba commented Nov 3, 2023

Do you have Office installed?

Windows doesn't have an exhaustive database built-in, it allows applications to register their own MIME types when they are installed.

@frankenstein91
Copy link
Author

I do not have office installed... but looks like Windows knows it
grafik

@zooba
Copy link
Member

zooba commented Nov 3, 2023

It may know a display name without having a MIME registration - those are separate things in Windows.

Your code works fine for me with Python 3.11 and Word installed, so I would assume it's simply not registered in your case. There's nothing we can do about that - send feedback to Microsoft through the Windows Feedback tool?

@frankenstein91
Copy link
Author

@zooba maybe Devs should than change https://docs.python.org/3/library/mimetypes.html from
The optional strict argument is a flag specifying whether the list of known MIME types is limited to only the official types [registered with IANA](https://www.iana.org/assignments/media-types/media-types.xhtml). When strict is True (the default), only the IANA types are supported; when strict is False, some additional non-standard but commonly used MIME types are also recognized.

To something like Only file types known to the operating system are recognized.

I personally find it very confusing otherwise

@zooba
Copy link
Member

zooba commented Nov 3, 2023

You're more than welcome to create a pull request with the updates. You'll find the Docs/library/mimetypes.rst in this repository.

@frankenstein91
Copy link
Author

Unfortunately English is not my mother tongue, I would suggest someone from the USA or the UK can formulate this much better than I can.
@patrickmccallum: sorry for linking you here... but do you have an idea how your database could be become a part of Python?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir easy stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
Status: Todo
Development

No branches or pull requests

5 participants
@iritkatriel @hugovk @zooba @frankenstein91 and others