use traceback.format_exc() instean of sys.exc_traceback