Python: Getting the error message of an exception

后端 未结 4 1503
孤独总比滥情好
孤独总比滥情好 2021-01-03 17:40

In python 2.6.6, how can I capture the error message of an exception.

IE:

response_dict = {} # contains info to response under a django view.
try:
           


        
4条回答
  •  粉色の甜心
    2021-01-03 18:25

    Pass it through str() first.

    response_dict.update({'error': str(e)})
    

    Also note that certain exception classes may have specific attributes that give the exact error.

提交回复
热议问题