I have tested all the scenarios when my django application run without meinheld, and there is no exception.
But exceptions occurs if application is run by meinheld.
Senario 1
The uploaded file is just a text file. It is wired that I uploaded a file of size 200kb successfully. Then I copy the content of this file and paste to double its size. The exception occurred when the second file is uploaded.
I tried to debug and found that function 'meinheld.input.read' returns a str which cannot concat to bytes.
The call stack is:
Traceback (most recent call last):
File "/home/dev/virtualenv/python3/lib/python3.4/site-packages/django/core/handlers/base.py", line 132, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/dev/virtualenv/python3/lib/python3.4/site-packages/django/contrib/admin/options.py", line 616, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
File "/home/dev/virtualenv/python3/lib/python3.4/site-packages/django/views/decorators/cache.py", line 57, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/home/dev/virtualenv/python3/lib/python3.4/site-packages/django/contrib/admin/sites.py", line 233, in inner
return view(request, *args, **kwargs)
File "/home/dev/virtualenv/python3/lib/python3.4/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
return view_func(*args, **kwargs)
File "/home/dev/d5_django_server/apps/product/admin.py", line 129, in change_view
return self.changeform_view(request, object_id, form_url, extra_context)
File "/home/dev/virtualenv/python3/lib/python3.4/site-packages/django/utils/decorators.py", line 34, in _wrapper
return bound_func(*args, **kwargs)
File "/home/dev/virtualenv/python3/lib/python3.4/site-packages/django/utils/decorators.py", line 106, in _wrapped_view
result = middleware.process_view(request, view_func, args, kwargs)
File "/home/dev/virtualenv/python3/lib/python3.4/site-packages/django/middleware/csrf.py", line 174, in process_view
request_csrf_token = request.POST.get('csrfmiddlewaretoken', '')
File "/home/dev/virtualenv/python3/lib/python3.4/site-packages/django/core/handlers/wsgi.py", line 137, in _get_post
self._load_post_and_files()
File "/home/dev/virtualenv/python3/lib/python3.4/site-packages/django/http/request.py", line 260, in _load_post_and_files
self._post, self._files = self.parse_file_upload(self.META, data)
File "/home/dev/virtualenv/python3/lib/python3.4/site-packages/django/http/request.py", line 225, in parse_file_upload
return parser.parse()
File "/home/dev/virtualenv/python3/lib/python3.4/site-packages/django/http/multipartparser.py", line 149, in parse
for item_type, meta_data, field_stream in Parser(stream, self._boundary):
File "/home/dev/virtualenv/python3/lib/python3.4/site-packages/django/http/multipartparser.py", line 626, in __iter__
for sub_stream in boundarystream:
File "/home/dev/virtualenv/python3/lib/python3.4/site-packages/django/http/multipartparser.py", line 439, in __next__
return LazyStream(BoundaryIter(self._stream, self._boundary))
File "/home/dev/virtualenv/python3/lib/python3.4/site-packages/django/http/multipartparser.py", line 466, in __init__
unused_char = self._stream.read(1)
File "/home/dev/virtualenv/python3/lib/python3.4/site-packages/django/http/multipartparser.py", line 337, in read
out = b''.join(parts())
File "/home/dev/virtualenv/python3/lib/python3.4/site-packages/django/http/multipartparser.py", line 330, in parts
chunk = next(self)
File "/home/dev/virtualenv/python3/lib/python3.4/site-packages/django/http/multipartparser.py", line 352, in __next__
output = next(self._producer)
File "/home/dev/virtualenv/python3/lib/python3.4/site-packages/django/http/multipartparser.py", line 414, in __next__
data = self.flo.read(self.chunk_size)
File "/home/dev/virtualenv/python3/lib/python3.4/site-packages/django/http/request.py", line 292, in read
return self._stream.read(*args, **kwargs)
File "/home/dev/virtualenv/python3/lib/python3.4/site-packages/django/core/handlers/wsgi.py", line 57, in read
result = self.buffer + self._read_limited(size - len(self.buffer))
TypeError: can't concat bytes to str
Senario 2
When a jpg is uploaded, the exception is different.
The call stack is:
Traceback (most recent call last):
File "/home/dev/virtualenv/python3/lib/python3.4/site-packages/django/core/handlers/base.py", line 132, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/dev/virtualenv/python3/lib/python3.4/site-packages/django/contrib/admin/options.py", line 616, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
File "/home/dev/virtualenv/python3/lib/python3.4/site-packages/django/views/decorators/cache.py", line 57, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/home/dev/virtualenv/python3/lib/python3.4/site-packages/django/contrib/admin/sites.py", line 233, in inner
return view(request, *args, **kwargs)
File "/home/dev/virtualenv/python3/lib/python3.4/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
return view_func(*args, **kwargs)
File "/home/dev/d5_django_server/apps/product/admin.py", line 129, in change_view
return self.changeform_view(request, object_id, form_url, extra_context)
File "/home/dev/virtualenv/python3/lib/python3.4/site-packages/django/utils/decorators.py", line 34, in _wrapper
return bound_func(*args, **kwargs)
File "/home/dev/virtualenv/python3/lib/python3.4/site-packages/django/utils/decorators.py", line 106, in _wrapped_view
result = middleware.process_view(request, view_func, args, kwargs)
File "/home/dev/virtualenv/python3/lib/python3.4/site-packages/django/middleware/csrf.py", line 174, in process_view
request_csrf_token = request.POST.get('csrfmiddlewaretoken', '')
File "/home/dev/virtualenv/python3/lib/python3.4/site-packages/django/core/handlers/wsgi.py", line 137, in _get_post
self._load_post_and_files()
File "/home/dev/virtualenv/python3/lib/python3.4/site-packages/django/http/request.py", line 260, in _load_post_and_files
self._post, self._files = self.parse_file_upload(self.META, data)
File "/home/dev/virtualenv/python3/lib/python3.4/site-packages/django/http/request.py", line 225, in parse_file_upload
return parser.parse()
File "/home/dev/virtualenv/python3/lib/python3.4/site-packages/django/http/multipartparser.py", line 149, in parse
for item_type, meta_data, field_stream in Parser(stream, self._boundary):
File "/home/dev/virtualenv/python3/lib/python3.4/site-packages/django/http/multipartparser.py", line 626, in __iter__
for sub_stream in boundarystream:
File "/home/dev/virtualenv/python3/lib/python3.4/site-packages/django/http/multipartparser.py", line 439, in __next__
return LazyStream(BoundaryIter(self._stream, self._boundary))
File "/home/dev/virtualenv/python3/lib/python3.4/site-packages/django/http/multipartparser.py", line 466, in __init__
unused_char = self._stream.read(1)
File "/home/dev/virtualenv/python3/lib/python3.4/site-packages/django/http/multipartparser.py", line 337, in read
out = b''.join(parts())
File "/home/dev/virtualenv/python3/lib/python3.4/site-packages/django/http/multipartparser.py", line 330, in parts
chunk = next(self)
File "/home/dev/virtualenv/python3/lib/python3.4/site-packages/django/http/multipartparser.py", line 352, in __next__
output = next(self._producer)
File "/home/dev/virtualenv/python3/lib/python3.4/site-packages/django/http/multipartparser.py", line 414, in __next__
data = self.flo.read(self.chunk_size)
File "/home/dev/virtualenv/python3/lib/python3.4/site-packages/django/http/request.py", line 292, in read
return self._stream.read(*args, **kwargs)
File "/home/dev/virtualenv/python3/lib/python3.4/site-packages/django/core/handlers/wsgi.py", line 57, in read
result = self.buffer + self._read_limited(size - len(self.buffer))
File "/home/dev/virtualenv/python3/lib/python3.4/site-packages/django/core/handlers/wsgi.py", line 45, in _read_limited
result = self.stream.read(size)
File "/home/dev/virtualenv/python3/lib/python3.4/codecs.py", line 313, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 1412: invalid start byte