Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何手动记录要与ereporter一起使用的异常?_Python_Google App Engine_Exception_Exception Handling - Fatal编程技术网

Python 如何手动记录要与ereporter一起使用的异常?

Python 如何手动记录要与ereporter一起使用的异常?,python,google-app-engine,exception,exception-handling,Python,Google App Engine,Exception,Exception Handling,我在GAE应用程序中使用,通过电子邮件通知所有未捕获的异常。但我也希望了解其他(已处理的)问题,因此,我使用以下代码: if something: pass else: logging.exception('something is wrong') 但ereporter在出现以下情况时失败:AttributeError: Traceback (most recent call last): File "/base/data/home/runtimes/python27/pyth

我在GAE应用程序中使用,通过电子邮件通知所有未捕获的异常。但我也希望了解其他(已处理的)问题,因此,我使用以下代码:

if something:
    pass
else:
    logging.exception('something is wrong')
但ereporter在出现以下情况时失败:
AttributeError

Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ereporter/ereporter.py", line 227, in emit
signature = self.__GetSignature(record.exc_info)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ereporter/ereporter.py", line 175, in __GetSignature
fulltype = '%s.%s' % (ex_type.__module__, ex_type.__name__)
AttributeError: 'NoneType' object has no attribute '__module__'

我理解为什么会这样——没有真正的例外。但是还有什么办法可以用ereporter记录这些案例吗?

正如你自己所说的那样——报告也不例外。由于
ereporter
似乎只报告异常,因此解决方案很明确:

if something:
    pass
else:
    try:
        raise Exception()
    except Exception:
         logging.exception('something is wrong')

尝试在日志记录中的消息之后添加exc_info=sys.exc_info()。异常call@TimHoffman,它将返回3
None
s(),让我试试。。谢谢。@TimHoffman,我刚刚试过了-没用,同样的错误也会发生。@TimHoffman:这就是
logging.exception()
在你自己没有传入
exc\u info
时已经做过的事情。这就是为什么会发生ereporter回溯,因为这里没有例外,首先要登录。