Skip navigation

I’ve created a tar.gz, yet Python’s mimetypes.guess_type() and my OS’ file command see it as two different mime.types:

$ file SPL-28435-etc_apps.tar.gz
SPL-28435-etc_apps.tar.gz: gzip compressed data, was "SPL-28435-etc_apps.tar",
last modified: Mon Dec 28 11:56:05 2009, max compression

$ python
Python 2.6.4 (r264:75706, Dec 16 2009, 06:15:35)
[GCC 4.0.1 (Apple Inc. build 5488)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import mimetypes
>>> mimetypes.guess_type('SPL-28435-etc_apps.tar.gz')
('application/x-tar', 'gzip')

If I attach this file to a JIRA with this mime-type and then download the file:

$ file SPL-28435-etc_apps.tar.gz
SPL-28435-etc_apps.tar.gz: data

If I attach the file to JIRA using the mime-type ‘application/x-gzip’ and then download the file:

$ file SPL-28435-etc_apps.tar.gz
SPL-28435-etc_apps.tar.gz:    gzip compressed data, was "SPL-28435-etc_apps.tar",
last modified: Mon Dec 28 11:56:05 2009, max compression

I’ve also tried overriding Python’s mime.magic without luck:

>>> from mimetypes import MimeTypes
>>> m = MimeTypes()
>>> m.read('/usr/share/file/magic.mime')
>>> m.guess_type('SPL-28435-etc_apps.tar.gz')
('application/x-tar', 'gzip')
Advertisement

2 Comments

  1. I know this is a bit old, but the “file” utility does not give a mime-type by default. Use file –mime-type and you’re likely to see something much closer to what python shows.

  2. This has made my day. I wish all psotgnis were this good.


Leave a Reply

Fill in your details below or click an icon to log in:

Gravatar
WordPress.com Logo

You are commenting using your WordPress.com account. Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.