[New-bugs-announce] [issue10490] mimetypes read_windows_registry fails for non-ASCII keys

And Clover report at bugs.python.org
Sun Nov 21 15:10:24 CET 2010

New submission from And Clover <and at doxdesk.com>:

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.

components: Library (Lib)
files: mimetypes-patch2-2.7.patch
keywords: patch
messages: 121929
nosy: aclover
priority: normal
severity: normal
status: open
title: mimetypes read_windows_registry fails for non-ASCII keys
versions: Python 2.7
Added file: http://bugs.python.org/file19745/mimetypes-patch2-2.7.patch

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list