1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] python exception message capturing

Discussão em 'Python' iniciado por Stack, Dezembro 19, 2024.

  1. Stack

    Stack Membro Participativo

    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))


    This doesn't seem to work, I get syntax error, what is the proper way of doing this for logging all kind of exceptions to a file

    Continue reading...

Compartilhe esta Página