import ftplib
import urllib2
import os
import logging
logger = logging.getLogger('ftpuploader')
hdlr = logging.FileHandler('ftplog.log')
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)
logger.setLevel(logging.INFO)
FTPADDR = "some ftp address"
def upload_to_ftp(con, filepath):
try:
f = open(filepath,'rb') # file to send
con.storbinary('STOR '+ filepath, f) # Send the file
f.close() # Close file and FTP
logger.info('File successfully uploaded to '+ FTPADDR)
except, e:
logger.error('Failed to upload to ftp: '+ str(e))
이것은 작동하지 않는 것 같습니다. 구문 오류가 발생합니다. 모든 종류의 예외를 파일에 기록하기 위해 이것을 수행하는 올바른 방법은 무엇입니까?
,후를 except, 당신은 얻을 것이다 global name 'e' is not defined더 나은 잘못된 구문 이하이다.
except Exception as e또는 이어야 except Exception, e합니다.
,후를 생략하십시오except.