简体   繁体   中英

Getting Django error with Debug False on django 1.7

I have Django 1.7 and i keep getting this error when i submit POST request to django.

If Debug is true then i don't get any error.

I have already looked at this

Setting DEBUG = False causes 500 Error

I added all address in ALLOWED_HOST but i keep getting error

[Django] ERROR (EXTERNAL IP): Internal Server Error:

    Internal Server Error: /api/user/edit
    Traceback (most recent call last):
     File "/srv/vhosts/site1/env/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 204, in get_response
       response = middleware_method(request, response)
     File "/srv/vhosts/site1/env/local/lib/python2.7/site-packages/htmlmin/middleware.py", line 41, in process_response
       if minify and self.can_minify_response(request, response):
     File "/srv/vhosts/site1/env/local/lib/python2.7/site-packages/htmlmin/middleware.py", line 32, in can_minify_response
       resp_ok = resp_ok and 'text/html' in response['Content-Type']
     File "/srv/vhosts/site1/env/local/lib/python2.7/site-packages/django/http/response.py", line 187, in __getitem__
       return self._headers[header.lower()][1]
    KeyError: 'content-type'

    Request repr(): 
    <WSGIRequest
    path://api/user/edit,
    GET:<QueryDict: {}>,
    POST:<QueryDict: {}>,
    COOKIES:{'csrftoken': 'HN2zP9edr2ItI5uW6tMocemUBczPiN4C',
    'sessionid': 'y10w8jqqertztttrol63bqtjfj8qa4c6'},
    META:{'CONTENT_LENGTH': '37',
    'CONTENT_TYPE': 'application/json;charset=UTF-8',
    u'CSRF_COOKIE': u'HN2zP9edr2ItI5uW6tMocemUBczPiN4C',
    'HTTP_ACCEPT': 'application/json, text/plain, */*',
    'HTTP_ACCEPT_ENCODING': 'gzip, deflate',
    'HTTP_ACCEPT_LANGUAGE': 'en-GB,en-US;q=0.8,en;q=0.6',
    'HTTP_CONNECTION': 'close',
    'HTTP_COOKIE': 'sessionid=y10w8jqqertztttrol63bqtjfj8qa4c6; csrftoken=HN2zP9edr2ItI5uW6tMocemUBczPiN4C',
    'HTTP_HOST': '104.60.4.102',
    'HTTP_ORIGIN': 'https://104.60.4.102,
    'HTTP_REFERER': 'https://104.60.4.102/users/',
    'HTTP_USER_AGENT': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36',
    'HTTP_X_CSRFTOKEN': 'HN2zP9edr2ItI5uW6tMocemUBczPiN4C',
    'HTTP_X_FORWARDED_FOR': '104.60.4.160',
    'PATH_INFO': u'//api/user/edit',
    'QUERY_STRING': '',
    'RAW_URI': '/api/user/edit',
    'REMOTE_ADDR': '',
    'REQUEST_METHOD': 'POST',
    'SCRIPT_NAME': u'',
    'SERVER_NAME': '104.60.4.102',
    'SERVER_PORT': '80',
    'SERVER_PROTOCOL': 'HTTP/1.0',
    'SERVER_SOFTWARE': 'gunicorn/19.0.0',
    'gunicorn.socket': <socket._socketobject object at 0x5daa910>,
    'wsgi.errors': <gunicorn.http.wsgi.WSGIErrorsWraper object at 0x5dbae10>,
    'wsgi.file_wrapper': <class 'gunicorn.http.wsgi.FileWrapper'>,
    'wsgi.input': <gunicorn.http.body.Body object at 0x5dbaf10>,
    'wsgi.multiprocess': True,
    'wsgi.multithread': False,
    'wsgi.run_once': False,
    'wsgi.url_scheme': 'http',
    'wsgi.version': (1, 0)}>

The REMOTE_ADDR is coming as '' if that can be the issue

The data gets posted fine to database but i get that error in firebug

Django-HTMLMin seems to be expecting that the key content-type should start with capital letters.

So see if you're setting the header content-type yourself and if so change to Content-Type .

I did a quick search in the repository for you, Django HTMLMIN repo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM