Http request with multiple files is not able to read by django server

93 views
Skip to first unread message

kousik chowdhury

unread,
Apr 25, 2014, 8:39:05 AM4/25/14
to django...@googlegroups.com
I am trying to send multiple files(images and audio) from an android device using `MultipartEntityBuilder` (java) with http request. Everytime request including files reaches server and is working as expected but sometimes(10%) django server is not able to read the content of the request.

After going through all the links related to this problem, I come to know that this problem may happen because of the **broken request** That is if someone cancelled the request in between.

As my request is an `AsyncTask` to the request should not break.


> I know this question is already asked. As I didn't get a proper solution from these posts, I want to reopen the issue. So instead of making this as `duplicate` ,please try to give me some light.

Links: -

 - http://stackoverflow.com/questions/15544124/django-unreadableposterror-request-data-read-error

 - http://stackoverflow.com/questions/3823280/ioerror-request-data-read-error/7089413





Server Log:

    Traceback (most recent call last):
      File "/var/www/html/prototype/version1/views.py", line 2515, in manage_app_data
        print request.FILES
      File "/usr/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 165, in _get_files
        self._load_post_and_files()
      File "/usr/local/lib/python2.7/site-packages/django/http/request.py", line 215, in _load_post_and_files
        self._post, self._files = self.parse_file_upload(self.META, data)
      File "/usr/local/lib/python2.7/site-packages/django/http/request.py", line 180, in parse_file_upload
        return parser.parse()
      File "/usr/local/lib/python2.7/site-packages/django/http/multipartparser.py", line 140, in parse
        for item_type, meta_data, field_stream in Parser(stream, self._boundary):
      File "/usr/local/lib/python2.7/site-packages/django/http/multipartparser.py", line 598, in __iter__
        for sub_stream in boundarystream:
      File "/usr/local/lib/python2.7/site-packages/django/utils/six.py", line 473, in next
        return type(self).__next__(self)
      File "/usr/local/lib/python2.7/site-packages/django/http/multipartparser.py", line 415, in __next__
        return LazyStream(BoundaryIter(self._stream, self._boundary))
      File "/usr/local/lib/python2.7/site-packages/django/http/multipartparser.py", line 441, in __init__
        unused_char = self._stream.read(1)
      File "/usr/local/lib/python2.7/site-packages/django/http/multipartparser.py", line 315, in read
        out = b''.join(parts())
      File "/usr/local/lib/python2.7/site-packages/django/http/multipartparser.py", line 308, in parts
        chunk = next(self)
      File "/usr/local/lib/python2.7/site-packages/django/utils/six.py", line 473, in next
        return type(self).__next__(self)
      File "/usr/local/lib/python2.7/site-packages/django/http/multipartparser.py", line 330, in __next__
        output = next(self._producer)
      File "/usr/local/lib/python2.7/site-packages/django/utils/six.py", line 473, in next
        return type(self).__next__(self)
      File "/usr/local/lib/python2.7/site-packages/django/http/multipartparser.py", line 391, in __next__
        data = self.flo.read(self.chunk_size)
      File "/usr/local/lib/python2.7/site-packages/django/http/request.py", line 244, in read
        six.reraise(UnreadablePostError, UnreadablePostError(*e.args), sys.exc_info()[2])
      File "/usr/local/lib/python2.7/site-packages/django/http/request.py", line 242, in read
        return self._stream.read(*args, **kwargs)
      File "/usr/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 51, in read
        result = self.buffer + self._read_limited(size - len(self.buffer))
      File "/usr/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 39, in _read_limited
        result = self.stream.read(size)
    UnreadablePostError: request data read error


How to fix ? what is going wrong?

Ilya Kazakevich

unread,
Apr 25, 2014, 9:25:12 AM4/25/14
to django...@googlegroups.com
Hello,


There may be some web-proxy between client and server that limits request size or time. Server may limit it as well.

* Remove all proxies between client and server
* Try to use different client (browser for example)
* Check your server configuration for request size and timeout.


Ilya Kazakevich,
JetBrains PyCharm (Best Python/Django IDE)
http://www.jetbrains.com/pycharm/
"Develop with pleasure!"
>--
>You received this message because you are subscribed to the Google Groups
>"Django users" group.
>To unsubscribe from this group and stop receiving emails from it, send an email to
>django-users...@googlegroups.com.
>To post to this group, send email to django...@googlegroups.com.
>Visit this group at http://groups.google.com/group/django-users.
>To view this discussion on the web visit
>https://groups.google.com/d/msgid/django-users/9f58b9cb-4ca6-48d6-aab4-649
>ec024142b%40googlegroups.com
><https://groups.google.com/d/msgid/django-users/9f58b9cb-4ca6-48d6-aab4-64
>9ec024142b%40googlegroups.com?utm_medium=email&utm_source=footer> .
>For more options, visit https://groups.google.com/d/optout.


Erik Cederstrand

unread,
Apr 25, 2014, 9:27:17 AM4/25/14
to Django Users
Den 25/04/2014 kl. 14.39 skrev kousik chowdhury <kousi...@gmail.com>:

> After going through all the links related to this problem, I come to know that this problem may happen because of the **broken request** That is if someone cancelled the request in between.
>
> As my request is an `AsyncTask` to the request should not break.

Clients can still abort the request or close the connection in many ways - the client application crashing, the device crashing, shutting down or running out of battery, losing network connection or switching networks etc.

You should probably just ignore these errors unless you suspect the error is happening despite any of the above reasons.

Erik
Reply all
Reply to author
Forward
0 new messages