-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
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
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
Comments
old implementation Lines 146 to 149 in 64a68c3
current implementation Lines 146 to 149 in 4802344
changing my small example adding both extensions ".r" and ".R" via $ python ./mimetest.py
mimetypes.types_map['.R'] = text/x-r-script , mimetypes.guess_type('example.R')[0] = text/x-r2-script import mimetypes
mimetypes.init()
MIMETYPE_ADDITIONAL_EXTENSIONS = [("text/x-r-script", ".R"), ("text/x-r2-script", ".r"),]
for (mimetype, extension) in MIMETYPE_ADDITIONAL_EXTENSIONS:
mimetypes.add_type(mimetype, extension, strict=True)
print("mimetypes.types_map['.R'] = %s , mimetypes.guess_type('example.R')[0] = %s" % (mimetypes.types_map['.R'],mimetypes.guess_type('example.R')[0])) With the current implementation 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 Lines 80 to 95 in 4802344
should change to become compatible with the changed implementation of guessing method mimetypes.guess_type .
|
Uh oh!
There was an error while loading. Please reload this page.
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 shouldmatch 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.Operating system and architecture:
Windows 10/WSL
Ubuntu
Small working example : mimetest.py
Running this via multiple Python versions is showing the problem:
perhaps this different behavior is a result of issue #64591
and its related merged pull requests
The text was updated successfully, but these errors were encountered: