Getting Rid of Django IOErrors

I run the Django site (via Apache / mod_python) and I use the features of Django to inform me and other developers about internal server errors. Sometimes such errors appear:

Traceback (most recent call last): File "/opt/webapp/externals/lib/django/core/handlers/base.py", line 92, in get_response response = callback(request, *callback_args, **callback_kwargs) File "/opt/webapp/csite/apps/customers/views.py", line 29, in feedback form = FeedbackForm(request.POST) File "/opt/webapp/externals/lib/django/core/handlers/modpython.py", line 113, in _get_post self._load_post_and_files() File "/opt/webapp/externals/lib/django/core/handlers/modpython.py", line 96, in _load_post_and_files self._post, self._files = http.QueryDict(self.raw_post_data, encoding=self._encoding), datastructures.MultiValueDict() File "/opt/webapp/externals/lib/django/core/handlers/modpython.py", line 163, in _get_raw_post_data self._raw_post_data = self._req.read() IOError: Client read error (Timeout?) 

As I understand it, those IOError generated by clients that are disconnected at the wrong time and that this is not a problem with my site.

If so: can I somehow turn off emails for these errors? I really do not want to know about errors that I cannot fix, and which are actually not errors.

+7
python django logging
03 Mar. '10 at 23:51
source share
3 answers

You should be able to write Middleware to catch the exception, and then you can β€œsilence” these specific exceptions.

https://docs.djangoproject.com/en/2.2/topics/http/middleware/

+2
Mar 04 '10 at 5:21
source share

Extending @ dlowe's solution to Django 1.3, we can write a complete working example like:

settings.py

 LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'filters': { 'supress_unreadable_post': { '()': 'common.logging.SuppressUnreadablePost', } }, 'handlers': { 'mail_admins': { 'level': 'ERROR', 'class': 'django.utils.log.AdminEmailHandler', 'filters': ['supress_unreadable_post'], } }, 'loggers': { 'django.request': { 'handlers': ['mail_admins'], 'level': 'ERROR', 'propagate': True, }, } } 

generic /logging.py

 import sys, traceback class SuppressUnreadablePost(object): def filter(self, record): _, exception, tb = sys.exc_info() if isinstance(exception, IOError): for _, _, function, _ in traceback.extract_tb(tb): if function == '_get_raw_post_data': return False return True 
+11
Apr 23 '12 at 16:05
source share

In django 1.3 and above, you can use the logging filter class to suppress exceptions that you are not interested in. Here's the log filter class that I use to limit IOError exceptions thrown from _get_raw_post_data() :

 import sys, traceback class _SuppressUnreadablePost(object): def filter(self, record): _, exception, tb = sys.exc_info() if isinstance(exception, IOError): for _, _, function, _ in traceback.extract_tb(tb): if function == '_get_raw_post_data': return False return True 

In Django 1.4, you can eliminate most of the complexity and suppress the new UnreadablePostError exception UnreadablePostError . (See this patch .)

+2
Feb 11 2018-12-12T00:
source share



All Articles