On Jul 29, 8:00 pm, Graham Dumpleton <[EMAIL PROTECTED]> wrote: > On Jul 29, 11:20 am, "Nimrod A. Abing" <[EMAIL PROTECTED]> wrote: > > > > > Hello, > > > I have recently begun testing LimitRequestBody to limit file uploads. > > It works but there are some issues. Whenever the uploaded file hits > > the limit, I get "Connection reset by peer". Ideally I would like to > > be able to redirect the user to an error page but it seems that Django > > tries to run but it hits an exception: > > > Traceback (most recent call last): > > > File > > "/opt/ActivePython/lib/python2.4/site-packages/django/core/handlers/base.py", > > line 77, in get_response > > response = callback(request, *callback_args, **callback_kwargs) > > > File > > "/opt/ActivePython/lib/python2.4/site-packages/django/db/transaction.py", > > line 194, in _commit_on_success > > res = func(*args, **kw) > > > File "/home/preownedcar/djangoapps/preownedcar/CoreApp/views.py", > > line 1108, in offer_post > > new_data = request.POST.copy() > > > File > > "/opt/ActivePython/lib/python2.4/site-packages/django/core/handlers/modpython.py", > > line 69, in _get_post > > self._load_post_and_files() > > > File > > "/opt/ActivePython/lib/python2.4/site-packages/django/core/handlers/modpython.py", > > line 50, in _load_post_and_files > > self._post, self._files = > > http.parse_file_upload(self._req.headers_in, self.raw_post_data) > > > File > > "/opt/ActivePython/lib/python2.4/site-packages/django/core/handlers/modpython.py", > > line 119, in _get_raw_post_data > > self._raw_post_data = self._req.read() > > > SystemError: Objects/stringobject.c:3518: bad argument to internal function > > This error message possibly relates to this bug in mod_python. > > https://issues.apache.org/jira/browse/MODPYTHON-234 > > We hadn't been able to come up with a way of reproducing the problem > on demand so hadn't yet been able to investigate. Where people had > seen this exception it was very rare and very random. > > I'll link this discussion to that issue as it may help finding > underlying problem in mod_python. > > > I get that traceback emailed to me every time an uploaded file hits > > the limit set by LimitRequestBody. > > > I am using Django 0.96 and this is on the production server. > > > Someone posted something similar on this list last December but the > > last question by the OP was never really addressed: > > >http://groups.google.com/group/django-users/browse_thread/thread/162a... > > > Has any progress been made with regards to handling 413 from within Django? > > FWIW, how mod_python handle the Apache LimitRequestBody directive is > wrong. I have it one of my TODO lists to log a bug against mod_python > for it. > > The problem is that mod_python doesn't check whether LimitRequestBody > would be triggered before actually calling the mod_python handler. > Thus, that the post data exceeds the limit is only found when > req.read() of mod_python request object is called and a Python > exception is generated because of an unknown read error. Well at least > it normally is an unknown read error. In your case you seem to be > triggered this other Python bug and getting that error instead. > > Now, because a read error of some sort is generated, mod_python > handlers would normally see it as an unexpected exception and it would > propagate back and result in a 500 Internal Server Error page rather > than a 413 error back to the client. Whether Django does anything > different or still sends back a 500 error page I don't know. > > In comparison, in mod_wsgi where I uncovered this problem with > LimitRequestBody, the code checks to see if LimitRequestBody would be > triggered before calling the WSGI application. If triggered the code > immediately returns without calling the application, returning the 413 > error. If an ErrorDocument for 413 is defined that would then be > invoked, else the standard Apache 413 error page would be returned. > > In summary, mod_python LimitRequestBody handling is broken. Even when > fixed, it would result in it being detected before Django is even > called and thus only custom error page can be one setup using > ErrorDocument directive of Apache. This ErrorDocument directive would > reference a Django URL if desired. > > Only other choice when using mod_python is not to use Apache > LimitRequestBody directive and for your actual Django URL handler to > check Content-Length of request itself and generate an appropriate 413 > error page. You wouldn't be able to apply it in one go for whole > Django application. > > If not bound to mod_python because of need to use it for custom > authentication/authorisation handlers connected to Django, you might > also try using mod_wsgi instead, where the LimitRequestBody directive > isn't a problem. > > Hope this helps to explain the issue.
And here is the mod_python issue I have created for the LimitRequestBody issue. https://issues.apache.org/jira/browse/MODPYTHON-240 I can now mark doing this off my TODO list. :-) Graham --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---