Alem / django-jfu

A Django Library for jQuery File Upload
BSD 3-Clause "New" or "Revised" License
148 stars 73 forks source link

KeyError: 'HTTP_ACCEPT_ENCODING' #16

Open thefoxbrain opened 10 years ago

thefoxbrain commented 10 years ago

Hi

Not sure if this is a django-jfu issue but I am getting the following errors during upload which django is email to the ADMIN email address. The images do seem to be uploading but its generating 100's of emails and I'm worried this is a more serious problem. Thanks

Traceback (most recent call last):

File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 114, in get_response response = wrapped_callback(request, _callback_args, *_callback_kwargs)

File "/usr/local/lib/python2.7/dist-packages/django/views/decorators/http.py", line 41, in inner return func(request, _args, *_kwargs)

File "/usr/django/htb/jfu/views.py", line 100, in upload return UploadResponse( request, file_dict )

File "/usr/django/htb/jfu/http.py", line 49, in init super( UploadResponse, self ).init( request, data, _args, *_kwargs )

File "/usr/django/htb/jfu/http.py", line 23, in init mime = j if j in request.META['HTTP_ACCEPT_ENCODING'] else 'text/plain'

KeyError: 'HTTP_ACCEPT_ENCODING'

<WSGIRequest path:/upload/, GET:<QueryDict: {u'club': [u'114'], u'gender': [u'2'], u'price': [u'3.00'], u'event': [u'30'], u'prop_bespoke': [u'5']}>, POST:<QueryDict: {u'csrfmiddlewaretoken': [u'p1RebfXufQx2IUdwNbm4dKktU0Mu5gEg']}>, COOKIES:{'_dc': '1', '_ga': 'GA1.2.811151867.1399232243', 'csrftoken': 'p1RebfXufQx2IUdwNbm4dKktU0Mu5gEg', 'sessionid': 'na16oa5yqjp10ka9uzqoddy92cktbrum'}, META:{'CONTENT_LENGTH': '5665409', 'CONTENT_TYPE': 'multipart/form-data; boundary=----WebKitFormBoundaryunOBVRBg0ZWRjB8d', u'CSRF_COOKIE': u'p1RebfXufQx2IUdwNbm4dKktU0Mu5gEg', 'DOCUMENT_ROOT': '/var/www', 'GATEWAY_INTERFACE': 'CGI/1.1', 'HTTPACCEPT': 'application/json, text/javascript, /_; q=0.01', 'HTTP_ACCEPT_LANGUAGE': 'en-US,en;q=0.8', 'HTTP_CACHE_CONTROL': 'max-age=259200', 'HTTP_CONNECTION': 'keep-alive', 'HTTP_COOKIE': 'sessionid=na16oa5yqjp10ka9uzqoddy92cktbrum; _dc=1; _ga=GA1.2.811151867.1399232243; csrftoken=p1RebfXufQx2IUdwNbm4dKktU0Mu5gEg', 'HTTP_HOST': 'www.example.com', 'HTTP_ORIGIN': 'http://www.example.com', 'HTTP_REFERER': 'http://www.example.com/upload1/', 'HTTP_USER_AGENT': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36', 'HTTP_VIA': '1.1 example.co.uk:3128 (squid/2.6.STABLE21)', 'HTTP_X_FORWARDED_FOR': '10.32.3.180', 'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest', 'PATH_INFO': u'/upload/', 'PATH_TRANSLATED': '/usr/django/htb/htb/wsgi.py/upload/', 'QUERY_STRING': '&event=30&price=3.00&club=114&gender=2&prop_bespoke=5', 'REMOTE_ADDR': '194.66.175.81', 'REMOTE_PORT': '59367', 'REQUEST_METHOD': 'POST', 'REQUEST_URI': '/upload/?&event=30&price=3.00&club=114&gender=2&prop_bespoke=5', 'SCRIPT_FILENAME': '/usr/django/htb/htb/wsgi.py', 'SCRIPT_NAME': u'', 'SERVER_ADDR': '172.31.8.216', 'SERVER_ADMIN': 'webmaster@localhost', 'SERVER_NAME': 'www.example.com', 'SERVER_PORT': '80', 'SERVER_PROTOCOL': 'HTTP/1.0', 'SERVER_SIGNATURE': '

Apache/2.2.22 (Ubuntu) Server at www.example.com Port 80
\n', 'SERVER_SOFTWARE': 'Apache/2.2.22 (Ubuntu)', 'mod_wsgi.application_group': 'ip-172-31-8-216.eu-west-1.compute.internal|', 'mod_wsgi.callable_object': 'application', 'mod_wsgi.enable_sendfile': '0', 'mod_wsgi.handler_script': '', 'mod_wsgi.input_chunked': '0', 'mod_wsgi.listener_host': '', 'mod_wsgi.listener_port': '80', 'mod_wsgi.process_group': '', 'mod_wsgi.queue_start': '1401201975006359', 'mod_wsgi.request_handler': 'wsgi-script', 'mod_wsgi.script_reloading': '1', 'mod_wsgi.version': (3, 4), 'wsgi.errors': <mod_wsgi.Log object at 0x7f27585156b0>, 'wsgi.file_wrapper': <built-in method file_wrapper of mod_wsgi.Adapter object at 0x7f2730131198>, 'wsgi.input': <mod_wsgi.Input object at 0x7f27399a2cb0>, 'wsgi.multiprocess': True, 'wsgi.multithread': True, 'wsgi.run_once': False, 'wsgi.url_scheme': 'http', 'wsgi.version': (1, 0)}>

thefoxbrain commented 10 years ago

If it helps the title of the emails django is generating is:

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

Could this have something to do with the ALLOWED_HOSTS setting?

thefoxbrain commented 10 years ago

I have done some testing and this only appears to be happening from certain locations\networks. I have a user uploading photos all day and they are seeing 'Error Internal Server Error' on each photo (even though they are being uploaded). I have just tried from another system completely and it's uploading fine. So I don't think this is a network or hosts issue. Given that the photos are uploading, can the HTTP_ACCEPT_ENCODING error be suppressed in some way? Could it be the size of the photo causing this?

Thanks, I love this project and I'm keen to help improve it.

thefoxbrain commented 10 years ago

Looking into this further it appears to be the issue is that HTTP_ACCEPT_ENCODING is not being set in the header by the sending server. I know in this case that the uploader is on an internal academic network so their network\admins could have suppressed this in some way. Can http.py be patched to do a 'try' on the request.META['HTTP_ACCEPT_ENCODING'] rather than assume it will always have a value?

Alem commented 10 years ago

Hello Rob, Thanks for bringing this to my attention, this is actually the result of a typo: that initializer should be using the key 'HTTP_ACCEPT', not 'HTTP_ACCEPT_ENCODING'. The former header lists the content-types accepted by the client (required to set the appropriate response content-type) while the latter lists the accepted content-encodings.

The correction has been pushed to the repository and is also present in the package hosted on PyPi. This should resolve the issue you were running into.

Best Regards, Z.

On Wed, May 28, 2014 at 03:51:18AM -0700, Rob Fox wrote:

Looking into this further it appears to be the issue is that HTTP_ACCEPT_ENCODING is not being set in the header by the sending server. I know in this case that the uploader is on an internal academic network so their network\admins could have suppressed this in some way. Can http.py be patched to do a 'try' on the request.META['HTTP_ACCEPT_ENCODING'] rather than assume it will always have a value?


Reply to this email directly or view it on GitHub: https://github.com/Alem/django-jfu/issues/16#issuecomment-44390183