Getting rid of Django IOErrors

后端 未结 3 1887
星月不相逢
星月不相逢 2021-01-02 19:54

I\'m running a Django site (via Apache/mod_python) and I use Django\'s facilities to inform me and other developers about internal server errors. Sometimes errors like those

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-02 20:32

    In django 1.3 and up, you can use a logging filter class to suppress the exceptions which you aren't interested in. Here's the logging filter class I'm using to narrowly suppress IOError exceptions raised 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 will be able to do away with most of the complexity and suppress the new exception class UnreadablePostError. (See this patch).

提交回复
热议问题