在python2.6.6中,如何捕获异常的错误消息.
即:
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