python get error message in except code example
Example 1: how to print error in try except python
try:
except Exception as e:
print("ERROR : "+str(e))
Example 2: python get exception message
try:
with open(filepath,'rb') as f:
con.storbinary('STOR '+ filepath, f)
logger.info('File successfully uploaded to '+ FTPADDR)
except Exception as e:
logger.error('Failed to upload to ftp: '+ str(e))
Example 3: python 3 except sys error info
1 import sys
2 try:
3 untrusted.execute()
4 except:
5 e = sys.exc_info()[0]
6 write_to_page( "<p>Error: %s</p>" % e )