[New-bugs-announce] [issue22347] mimetypes.guess_type("//example.com") misinterprets host name as file name
Martin Panter
report at bugs.python.org
Sat Sep 6 04:52:37 CEST 2014
New submission from Martin Panter:
The documentation says that guess_type() takes a URL, but:
>>> mimetypes.guess_type("http://example.com")
('application/x-msdownload', None)
I suspect the MS download is a reference to *.com files (like DOS's command.com). My current workaround is to strip out the host name from the URL, since I cannot imagine it would be useful for determining the content type. I am also stripping the fragment part. An argument could probably be made for stripping the “;parameters” and “?query” parts as well.
>>> # Workaround for mimetypes.guess_type("//example.com")
... # interpreting host name as file name
... url = urlparse("http://example.com")
>>> url = net.url_replace(url, netloc="", fragment="")
>>> url
'http://'
>>> mimetypes.guess_type(url, strict=False)
(None, None)
----------
components: Library (Lib)
messages: 226467
nosy: vadmium
priority: normal
severity: normal
status: open
title: mimetypes.guess_type("//example.com") misinterprets host name as file name
type: behavior
versions: Python 3.4
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22347>
_______________________________________
More information about the New-bugs-announce
mailing list