[New-bugs-announce] [issue32462] mimetypes.guess_type() might be return None or a tuple with (type/subtype, encoding)

Cheryl Sabella report at bugs.python.org
Sun Dec 31 06:07:49 EST 2017


New submission from Cheryl Sabella <chekat2 at gmail.com>:

On a Windows 7 system, entering the following:

    >>> mime, encoding = mimetypes.guess_type('Untitled.sql')
    >>> mime
    'text\\plain'

Meaning, the return value is 'text\\plain' instead of 'text/plain'.  Tracking this down, it's due to .sql being loaded from the Windows registry and the registry is using the wrong slash.

The mimetypes.guess_type() documentation states:
> The return value is a tuple (type, encoding) where type is None if    > the type can’t be guessed (missing or unknown suffix) or a string of
> the form 'type/subtype', usable for a MIME content-type header.

I don't know if guess_type() (or add_types) should check for a valid types, if .sql should be added to the valid types (it's on the IANA page), or if the documentation should be fixed so it doesn't look like a guarantee.  Or all three.  :-)

----------
components: Library (Lib)
messages: 309275
nosy: csabella
priority: normal
severity: normal
status: open
title: mimetypes.guess_type() might be return None or a tuple with (type/subtype, encoding)
type: behavior
versions: Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32462>
_______________________________________


More information about the New-bugs-announce mailing list