Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception raised when no content type set: "Error in formatting: KeyError: u'content-type'" #98

Closed
JoeJasinski opened this issue Mar 12, 2016 · 2 comments
Labels

Comments

@JoeJasinski
Copy link

Hi,

When the content-type is not available in the response, the following exception is raised. I encounter this error when serving up static media with django-filer, but it looks like this could happen in any case where the request['Content-Type'] is not present.

`
Environment:

Request Method: GET
Request URL: http://localhost:8000/media/filer_public/df/66/df664fc4-d8a6-4d88-8aef-7be5e3aef32a/chipy-05-chicago_flag_python_logo-01.jpg

Django Version: 1.9.4
Python Version: 2.7.9
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sitemaps',
'djangocms_admin_style',
'django.contrib.admin',
'easy_thumbnails',
'mptt',
'filer',
'nocaptcha_recaptcha',
'cms',
'treebeard',
'menus',
'sekizai',
'reversion',
'sorl.thumbnail',
'django_extensions',
'pagefeature',
'contact_form',
'photo_gallery.apps.PhotoConfig',
'djangocms_inherit',
'djangocms_teaser',
'djangocms_link',
'djangocms_snippet',
'djangocms_text_ckeditor',
'djangocms_plain_text')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'htmlmin.middleware.HtmlMinifyMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'cms.middleware.user.CurrentUserMiddleware',
'cms.middleware.page.CurrentPageMiddleware',
'cms.middleware.toolbar.ToolbarMiddleware',
'cms.middleware.language.LanguageCookieMiddleware',
'htmlmin.middleware.MarkRequestMiddleware')

Traceback:

File "/Users/jjasinski/Sites/joejasinski/envs/joejasinski/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response

  1.             response = middleware_method(request, response)
    

File "/mysite/mysite/envs/mysite/lib/python2.7/site-packages/htmlmin/middleware.py" in process_response

  1.     if minify and self.can_minify_response(request, response):
    

File "/mysite/envs/mysite/lib/python2.7/site-packages/htmlmin/middleware.py" in can_minify_response

  1.     resp_ok = 'text/html' in response['Content-Type']
    

File "/mysite/envs/mysite/lib/python2.7/site-packages/django/http/response.py" in getitem

  1.     return self._headers[header.lower()][1]
    

Exception Type: KeyError at /media/filer_public/df/66/df664fc4-d8a6-4d88-8aef-7be5e3aef32a/chipy-05-chicago_flag_python_logo-01.jpg
Exception Value: 'content-type'
`

@atten
Copy link

atten commented Mar 20, 2016

I also viewed this bug while requesting files from MEDIA_URL with DEBUG=True.
It looks like you need to add additional check for existence 'Content-Type' in response (htmlmin/middleware.py:32).

@andrewsmedina
Copy link
Member

released in 0.9.1 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants