[Django] #20162: Wrong mimetype for SVG files under Python 2.6

43 views
Skip to first unread message

Django

unread,
Mar 29, 2013, 10:45:57 PM3/29/13
to django-...@googlegroups.com
#20162: Wrong mimetype for SVG files under Python 2.6
----------------------------------------+------------------------
Reporter: julien | Owner: julien
Type: Bug | Status: new
Component: Core (Other) | Version: 1.5
Severity: Normal | Keywords:
Triage Stage: Accepted | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
----------------------------------------+------------------------
There's a bug in Python 2.6 where the mimetypes module returns the wrong
value for SVG files:

{{{#!python
Python 2.6.6 (r266:84292, Feb 22 2013, 00:00:18)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
>>> import mimetypes
>>> mimetypes.guess_type('blah.svg')
(None, None)
}}}

This is fixed in Python 2.7:

{{{#!python
Python 2.7.2 (default, Mar 2 2012, 16:57:52)
[GCC 4.2.1 Compatible Apple Clang 3.1 (tags/Apple/clang-318.0.45)] on
darwin
>>> import mimetypes
>>> mimetypes.guess_type('blah.svg')
('image/svg+xml', None)
}}}

Django's `static.serve()` view should be made smarter to always return
`image/svg+xml` regardless of the Python version.

--
Ticket URL: <https://code.djangoproject.com/ticket/20162>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 29, 2013, 11:28:10 PM3/29/13
to django-...@googlegroups.com
#20162: Wrong mimetype for SVG files under Python 2.6
------------------------------+------------------------------------
Reporter: julien | Owner: julien
Type: Bug | Status: closed

Component: Core (Other) | Version: 1.5
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------
Changes (by charettes):

* status: new => closed
* resolution: => invalid


Comment:

It looks like `.svg` was only included in the default
`mimetypes.types_map` in [http://bugs.python.org/issue10730 python 3.2].

I guess running `mimetype blah.svg` in a terminal on your Red Hat box
wouldn't return any result either.

It worked on python 2.6 on my machine:

{{{
#!python
Python 2.6.8 (default, Sep 21 2012, 13:41:09)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.


>>> import mimetypes
>>> mimetypes.guess_type('blah.svg')
('image/svg+xml', None)
}}}

Because the `mimetypes.types_map` is populated from different files on
your OS (/etc/mime.types on my box) which contains mimetypes mappings.

All in all this is not a Django issue nor a Python one. You should either
configure your OS or issue a `mimetypes.add_type('image/svg+xml', '.svg')`
within your app.

--
Ticket URL: <https://code.djangoproject.com/ticket/20162#comment:1>

Django

unread,
Mar 30, 2013, 4:15:19 AM3/30/13
to django-...@googlegroups.com
#20162: Wrong mimetype for SVG files under Python 2.6
------------------------------+------------------------------------
Reporter: julien | Owner: julien
Type: Bug | Status: closed

Component: Core (Other) | Version: 1.5
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------

Comment (by julien):

I disagree. Although at the root this might be an issue with the OS,
Python can step up to get around the issue — just like it did with that
commit in Python 3.2. Similarly, I believe Django should do the same since
it supports Python >= 2.6 and SVG is now an essential part of the Web. I
think that by doing this Django would fill its role as a Web framework.

Chrome (and probably other browsers) simply will not render SVG images if
they are not served with the right mimetype. Using `mimetype.add_type()`
in my app just because I'm using a Red Hat box feels like a counter-
intuitive hack to me. In my mind Django should just work for this type of
trivial things, regardless of the OS it is served from.

Let's catch up and discuss this on IRC. Cheers!

--
Ticket URL: <https://code.djangoproject.com/ticket/20162#comment:2>

Django

unread,
Mar 30, 2013, 5:25:33 AM3/30/13
to django-...@googlegroups.com
#20162: Wrong mimetype for SVG files under Python 2.6
------------------------------+------------------------------------
Reporter: julien | Owner: julien
Type: Bug | Status: closed

Component: Core (Other) | Version: 1.5
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------

Comment (by claudep):

I think I would also categorize that in platform weakness. If the issue
can simply be resolved by adding the proper mime type in `/etc/mime.types`
on your platform, I'm not in favour of fixing it in Django. Fixing it at
platform level has also the advantage that it might also solve the issue
for any Web server (in the case they use that information source also, not
verified).

--
Ticket URL: <https://code.djangoproject.com/ticket/20162#comment:3>

Django

unread,
Mar 30, 2013, 3:13:04 PM3/30/13
to django-...@googlegroups.com
#20162: Wrong mimetype for SVG files under Python 2.6
--------------------------------------+------------------------------------
Reporter: julien | Owner: julien
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by charettes):

* status: closed => new
* type: Bug => Cleanup/optimization
* version: 1.5 => master
* component: Core (Other) => Documentation
* resolution: invalid =>


Comment:

As discussed with claudep and julien on IRC I'm re-opening as a
documentation enhancement.

We should document `static.serve()` limitation and how to properly solves
it by configuring your system.

--
Ticket URL: <https://code.djangoproject.com/ticket/20162#comment:4>

Django

unread,
Mar 30, 2013, 3:18:16 PM3/30/13
to django-...@googlegroups.com
#20162: Document `static.serve()` limitation concerning missing system wide
mimetypes.
--------------------------------------+------------------------------------
Reporter: julien | Owner: julien

Type: Cleanup/optimization | Status: new
Component: Documentation | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

--
Ticket URL: <https://code.djangoproject.com/ticket/20162#comment:5>

Django

unread,
Mar 30, 2013, 7:23:51 PM3/30/13
to django-...@googlegroups.com
#20162: Document `static.serve()` limitation concerning missing system wide
mimetypes.
--------------------------------------+------------------------------------
Reporter: julien | Owner: julien
Type: Cleanup/optimization | Status: closed
Component: Documentation | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Julien Phalip <jphalip@…>):

* status: new => closed

* resolution: => fixed


Comment:

In [changeset:"ffc8e2e0ae9f1e35f4b7c78e6235bd0e3ba41aa9"]:
{{{
#!CommitTicketReference repository=""
revision="ffc8e2e0ae9f1e35f4b7c78e6235bd0e3ba41aa9"
Fixes #20162 -- Added a note in the documentation for `static.serve()`
about the need for updating the system's map files when incorrect content
types are returned. Many thanks to Simon Charette and Claude Paroz for
their feedback.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/20162#comment:6>

Reply all
Reply to author
Forward
0 new messages