python exception message capturing

前端 未结 11 1701
醉梦人生
醉梦人生 2020-12-12 09:06
import ftplib
import urllib2
import os
import logging
logger = logging.getLogger(\'ftpuploader\')
hdlr = logging.FileHandler(\'ftplog.log\')
formatter = logging.Form         


        
11条回答
  •  清歌不尽
    2020-12-12 09:42

    There are some cases where you can use the e.message or e.messages.. But it does not work in all cases. Anyway the more safe is to use the str(e)

    try:
      ...
    except Exception as e:
      print(e.message)
    

提交回复
热议问题