草庐IT

IGNORE_EXCEPTION_DETAIL

全部标签

python - Sentry/乌鸦与 django : how to ignore certain exceptions?

我希望sentry/raven忽略某个函数或django模块的所有异常,但是查看文档和代码,我只看到一个选项可以通过向其添加额外的属性来忽略自定义异常。有没有办法通过函数名或模块名来忽略异常?谢谢! 最佳答案 阅读raven的源代码,我发现如果您想忽略某些异常,您可以将它们添加到IGNORE_EXCEPTIONS中,如下所示:RAVEN_CONFIG={'dsn':'...','IGNORE_EXCEPTIONS':['exceptions.ZeroDivisionError','some.other.module.CustomEx

python - 对自定义 Exception 的 try/except 感到困惑

我的代码:classAError(Exception):print'erroroccur'foriinrange(3):try:print'---oo'raiseAErrorexceptAError:print'getAError'else:print'goingon'finally:print'finally'当我运行上面的代码时,输​​出是这样的:erroroccur---oogetAErrorfinally---oogetAErrorfinally---oogetAErrorfinally我认为字符串"erroroccur"应该出现三次,比如"---oo",但它只出现了一次;为什

python - 替换非字母数字字符,除了一些异常(exception) python

在perl中s/[^\w:]//g将替换所有非字母数字字符EXCEPT:在python中,我使用re.sub(r'\W+','',mystring)它确实删除了除_下划线之外的所有非字母数字。有什么办法可以放置异常(exception),我不希望替换=和.之前我使用了另一种方法,即使用re.sub('[!@#\'\"$()]','',mystring`)替换所有不需要的字符但是,我无法预测mystring中可能出现的所有字符,因此我希望删除除少数字符之外的所有非字母数字字符。Google没有提供合适的答案。最近的搜索是pythonregexsplitany\W+withsomeexce

没有参数的 Python 'raise' : what is "the last exception that was active in the current scope"?

Python的文档说:Ifnoexpressionsarepresent,raisere-raisesthelastexceptionthatwasactiveinthecurrentscope.(Python3:https://docs.python.org/3/reference/simple_stmts.html#raise;Python2.7:https://docs.python.org/2.7/reference/simple_stmts.html#raise。)但是,“最后激活”的概念似乎已经改变。见证以下代码示例:#from__future__importprint_f

python - django rest 框架 - 使用 detail_route 和 detail_list

在我的代码中,我有一个用户View集。我想要的是只允许读取操作(/users/42和/users/),ReadOnlyModelViewSet做得很好。此外,我想要一个/users/registerURL,我可以POST到该URL以注册新用户。classUserViewSet(viewsets.ReadOnlyModelViewSet):queryset=User.objects.all()serializer_class=UserSerializer@list_route(methods=['post'])defregister(request):serializer=UserSer

python - 为什么 "except Exception"没有捕捉到 SystemExit?

isinstance(SystemExit(1,),Exception)评估为True,但此代码段打印“caughtbybareexceptSystemExit(1,)”。try:sys.exit(0)exceptException,e:print'caughtbyexceptException',str(e)except:print'caughtbybareexcept',repr(sys.exc_info()[1])我的测试环境是Python2.6。 最佳答案 isinstance(SystemExit(1),异常)在Pytho

python - 无一异常(exception)地获取 python 回溯

假设您有这些模块:模块1.pyimportmodule2defa():module1.b()defc():print"Higuys!"模块2.pyimportmodule1defb():module1.c()我想要一个函数func(a())产生与此类似的输出:(=atraceback?)/usr/local/lib/python2.7/dist-packages/test/module1.py3defa():4module1.b()1importmodule1/usr/local/lib/python2.7/dist-packages/test/module2.py3defb():4m

python - 为什么 `if Exception` 在 Python 中工作

在这个答案https://stackoverflow.com/a/27680814/3456281中,提出了以下结构a=[1,2]whileTrue:ifIndexError:print("Stopped.")breakprint(a[2])实际上打印“已停止”。和中断(使用Python3.4.1测试)。为什么?!为什么ifIndexError甚至是合法的?为什么a[2]不会在没有try...except的情况下引发IndexError? 最佳答案 所有对象都有一个boolean值。如果没有另外定义,则该boolean值为True。

python: raise child_exception, OSError: [Errno 2] 没有那个文件或目录

我使用subprocess.popen()函数在python中执行命令,如下所示:omp_cmd='cat%s|omp-h%s-u%s-w%s-p%s-X-'%(temp_xml,self.host_IP,self.username,self.password,self.port)xmlResult=Popen(omp_cmd,stdout=PIPE,stderr=STDOUT)在shell中它运行良好没有错误,但在python中我得到:File"/home/project/vrm/apps/audit/models.py",line148,insendOMPxmlResult=Pop

python - Django:反转 'detail',参数为 '(' ',)' and keyword arguments ' {}' 未找到

我正在按照官方教程学习Django并使用1.5。我有这个链接作为我的索引模板的一部分,它工作正常:{{poll.question}}但是,这是硬编码的,教程建议更好的方法是使用:{{poll.question}}这样你在处理大量模板时会更好,你必须对url进行更改。由于我进行了上述更改,因此在运行该应用程序时出现以下错误:ExceptionType:NoReverseMatchExceptionValue:Reversefor'detail'witharguments'('',)'andkeywordarguments'{}'notfound.我的urls.py看起来像这样:fromd