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
str()
最初に通過させます。
response_dict.update({'error': str(e)})
また、特定の例外クラスには、正確なエラーを示す特定の属性がある場合があることに注意してください。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加