【发布时间】:2011-05-26 12:43:40
【问题描述】:
在python 2.6.6中,如何捕获异常的错误信息。
IE:
response_dict = {} # contains info to response under a django view.
try:
plan.save()
response_dict.update({'plan_id': plan.id})
except IntegrityError, e: #contains my own custom exception raising with custom messages.
response_dict.update({'error': e})
return HttpResponse(json.dumps(response_dict), mimetype="application/json")
这似乎不起作用。我明白了:
IntegrityError('Conflicts are not allowed.',) is not JSON serializable
【问题讨论】:
-
“这似乎不起作用。” - 它应该做什么和不做什么?
-
您使用的是哪个版本的 Python?
-
您好,我已经更新了我的问题。谢谢
标签: python django exception-handling