You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
mimetypes.guess_type could not find mimetypes added by mimetypes.add_type i.e. in PY3.10.4 // OR : different return values (PY2.7 to PY3.9.7) vs (PY3.9.11 to PY3.10.4) #92455
I think something is broken in mimetype.guess_type or documentation did not cover the change ...
A small working example and its outputs for different Python versions are listed below.
In this example the value from a concrete mimetypes.types_map entry should
match to the returnvalue of mimetypes.guess_type in all tested Python versions:
But it did not; the return value of mimetypes.guess_type is wrong from my point of view.
changed the title [-]mimetype.guess_type : different return values (PY2.7 to PY3.9.7) vs (PY3.9.11 to PY3.10.4)[/-][+][proposed lables: stdlib, 3.9, 3.10, 3.11] mimetype.guess_type : different return values (PY2.7 to PY3.9.7) vs (PY3.9.11 to PY3.10.4)[/+]on May 22, 2022
changed the title [-][proposed lables: stdlib, 3.9, 3.10, 3.11] mimetype.guess_type : different return values (PY2.7 to PY3.9.7) vs (PY3.9.11 to PY3.10.4)[/-][+][proposed lables: stdlib, 3.9, 3.10, 3.11] mimetype.guess_type could not find mimetypes added by mimetypes.add_type i.e. in PY3.10.4 // OR : different return values (PY2.7 to PY3.9.7) vs (PY3.9.11 to PY3.10.4)[/+]on May 23, 2022
changed the title [-][proposed lables: stdlib, 3.9, 3.10, 3.11] mimetype.guess_type could not find mimetypes added by mimetypes.add_type i.e. in PY3.10.4 // OR : different return values (PY2.7 to PY3.9.7) vs (PY3.9.11 to PY3.10.4)[/-][+][proposed lables: stdlib, 3.9, 3.10, 3.11] mimetypes.guess_type could not find mimetypes added by mimetypes.add_type i.e. in PY3.10.4 // OR : different return values (PY2.7 to PY3.9.7) vs (PY3.9.11 to PY3.10.4)[/+]on May 23, 2022
changed the title [-][proposed lables: stdlib, 3.9, 3.10, 3.11] mimetypes.guess_type could not find mimetypes added by mimetypes.add_type i.e. in PY3.10.4 // OR : different return values (PY2.7 to PY3.9.7) vs (PY3.9.11 to PY3.10.4)[/-][+]mimetypes.guess_type could not find mimetypes added by mimetypes.add_type i.e. in PY3.10.4 // OR : different return values (PY2.7 to PY3.9.7) vs (PY3.9.11 to PY3.10.4)[/+]on Apr 7, 2023
There are also other issues. If we register an upper-case suffix, the lower-case suffix will not match. It is difficult to make it matching while keep distinction between different types for lower-case and upper-case suffixes, so we perhaps should leave this. But all this is undocumented. It should be documented.
There is question about the order. If we cannot find the exact match for an upper-case suffix in the strict mapping, should we try next the exact match in the non-strict mapping or the case-insensitive match in the strict mapping?
Activity
ifrh commentedon May 8, 2022
old implementation
cpython/Lib/mimetypes.py
Lines 146 to 149 in 64a68c3
current implementation
cpython/Lib/mimetypes.py
Lines 146 to 149 in 4802344
changing my small example adding both extensions ".r" and ".R" via
mimetypes.add_typegivesWith the current implementation
mimetypes.guess_typecannot guess "own" mimetypes which had been added using uppercase letters.In the docs https://docs.python.org/3/library/mimetypes.html#mimetypes.add_type there is not written, that mimetypes must be written in lowercase letters.
As you can see the implementation of
add_typecan add "file endings" with capital letters, but they cannot find viamimetypes.guess_typeanymore:cpython/Lib/mimetypes.py
Lines 80 to 95 in 4802344
should change to become compatible with the changed implementation of guessing method
mimetypes.guess_type.[-]mimetype.guess_type : different return values (PY2.7 to PY3.9.7) vs (PY3.9.11 to PY3.10.4)[/-][+][proposed lables: stdlib, 3.9, 3.10, 3.11] mimetype.guess_type : different return values (PY2.7 to PY3.9.7) vs (PY3.9.11 to PY3.10.4)[/+][-][proposed lables: stdlib, 3.9, 3.10, 3.11] mimetype.guess_type : different return values (PY2.7 to PY3.9.7) vs (PY3.9.11 to PY3.10.4)[/-][+][proposed lables: stdlib, 3.9, 3.10, 3.11] mimetype.guess_type could not find mimetypes added by mimetypes.add_type i.e. in PY3.10.4 // OR : different return values (PY2.7 to PY3.9.7) vs (PY3.9.11 to PY3.10.4)[/+][-][proposed lables: stdlib, 3.9, 3.10, 3.11] mimetype.guess_type could not find mimetypes added by mimetypes.add_type i.e. in PY3.10.4 // OR : different return values (PY2.7 to PY3.9.7) vs (PY3.9.11 to PY3.10.4)[/-][+][proposed lables: stdlib, 3.9, 3.10, 3.11] mimetypes.guess_type could not find mimetypes added by mimetypes.add_type i.e. in PY3.10.4 // OR : different return values (PY2.7 to PY3.9.7) vs (PY3.9.11 to PY3.10.4)[/+][-][proposed lables: stdlib, 3.9, 3.10, 3.11] mimetypes.guess_type could not find mimetypes added by mimetypes.add_type i.e. in PY3.10.4 // OR : different return values (PY2.7 to PY3.9.7) vs (PY3.9.11 to PY3.10.4)[/-][+]mimetypes.guess_type could not find mimetypes added by mimetypes.add_type i.e. in PY3.10.4 // OR : different return values (PY2.7 to PY3.9.7) vs (PY3.9.11 to PY3.10.4)[/+]iritkatriel commentedon Apr 7, 2023
CC @kumaraditya303
ifrh commentedon Apr 19, 2026
just a ping. behavior is buggy in same way in newer Python versions than testet before (i.e. Python 3.13.11)
pythongh-92455: Respect case-sensitive mimetype suffixes
yuanx749 commentedon May 20, 2026
Friendly ping. PR #148782 is available for this issue.
serhiy-storchaka commentedon Jun 5, 2026
There are also other issues. If we register an upper-case suffix, the lower-case suffix will not match. It is difficult to make it matching while keep distinction between different types for lower-case and upper-case suffixes, so we perhaps should leave this. But all this is undocumented. It should be documented.
There is question about the order. If we cannot find the exact match for an upper-case suffix in the strict mapping, should we try next the exact match in the non-strict mapping or the case-insensitive match in the strict mapping?
gh-92455: Respect case-sensitive mimetype suffixes (GH-148782)
pythongh-92455: Respect case-sensitive mimetype suffixes (pythonGH-14…