1 import traceback 2 3 4 def get_stacktrace(error): 5 msg = repr(error) 6 try: 7 tb = traceback.format_exception(error) 8 return (msg + "".join(tb)).strip() 9 except Exception: 10 return msg