This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: mimetypes read_windows_registry fails for non-ASCII keys
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution:
Dependencies: Superseder: mimetypes initialization fails on Windows because of non-Latin characters in registry
View: 9291
Assigned To: Nosy List: aclover, r.david.murray
Priority: normal Keywords: patch

Created on 2010-11-21 14:10 by aclover, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
mimetypes-patch2-2.7.patch aclover, 2010-11-21 14:13 remove troublesome encode
Messages (2)
msg121929 - (view) Author: And Clover (aclover) * Date: 2010-11-21 14:10
The `enum_types` function in `MimeTypes.read_windows_registry` tries to `.encode` the results of `EnumKey`, assuming it to be a Unicode string.

However, `_winreg.EnumKey` in Python 2.x actually returns a byte string (straight from the ANSI version of the registry interface). Consequently, if there is a MIME type registered with a non-ASCII character in its name (invalid, but not unheard of), initialising `MimeTypes` will raise a `UnicodeDecodeError`. This is not caught (it is only expecting a `UnicodeEncodeError`), so it bombs out whatever module indirectly caused `mimetypes.init()` to be called.

This attempt to `.encode` the `ctype` should simply be removed.
msg122163 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-11-22 20:24
This is a duplicate if issue 9291.
History
Date User Action Args
2022-04-11 14:57:09adminsetgithub: 54699
2010-11-22 20:24:33r.david.murraysetstatus: open -> closed

nosy: + r.david.murray
messages: + msg122163

superseder: mimetypes initialization fails on Windows because of non-Latin characters in registry
stage: resolved
2010-11-22 14:02:29acloversettype: behavior
2010-11-21 14:13:08acloversetfiles: + mimetypes-patch2-2.7.patch
2010-11-21 14:12:52acloversetfiles: - mimetypes-patch2-2.7.patch
2010-11-21 14:10:23aclovercreate