Форум сайта python.su
103
ну даже не знаю…
попробуйте так, что оно скажет
import os, glob, zipfile, fileinput, shutil, time, logging, re, datetime, socket import dateutil.relativedelta from logging import handlers from lxml import etree LOG_FILENAME = 'G:\log_in.txt' FROM = '~@~.ru' TO = '~@~.ru' SUBJECT = 'INFO - Ins' try: logger = logging.getLogger('Logging') logger.setLevel(logging.DEBUG) logrotate = logging.handlers.RotatingFileHandler(LOG_FILENAME, maxBytes=9000, backupCount=2) logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s') handler = handlers.SMTPHandler(('192.168.1.5', 25), FROM, TO, SUBJECT) email_logger = logging.getLogger('~@~.ru') email_logger.addHandler(handler) email_logger.setLevel = logging.info dir_ins = "G:\\INS\\" os.chdir("G:/F/D") for file in glob.glob("*.zip"): if os.path.splitext(file)[0] == '630': if not os.path.exists(dir_ins): os.makedirs(dir_ins) email_logger.info("INS " + time.strftime("%d-%m-%Y",time.localtime(os.path.getmtime(file)))) logging.debug("INSURED " + time.strftime("%d-%m-%Y",time.localtime(os.path.getmtime(file))) + " - " + str(os.path.getsize(file))) shutil.move(os.path.abspath(file), dir_ins) except socket.timeout: logging.warning("Warning! SMTP server - TimeOut!")
Офлайн
857
from logging import handlers class A: filename = 'file' lineno = 1 handler = handlers.SMTPHandler(('localhost', 25), 'x@x', 'y@y', 'subj') handler.emit(A())
class SMTPHandler(logging.Handler): """ A handler class which sends an SMTP email for each logging event. """ def __init__(self, mailhost, fromaddr, toaddrs, subject, credentials=None, secure=None): """ Initialize the handler. Initialize the instance with the from and to addresses and subject line of the email. To specify a non-standard SMTP port, use the (host, port) tuple format for the mailhost argument. To specify authentication credentials, supply a (username, password) tuple for the credentials argument. To specify the use of a secure protocol (TLS), pass in a tuple for the secure argument. This will only be used when authentication credentials are supplied. The tuple will be either an empty tuple, or a single-value tuple with the name of a keyfile, or a 2-value tuple with the names of the keyfile and certificate file. (This tuple is passed to the `starttls` method). """ logging.Handler.__init__(self) if isinstance(mailhost, tuple): self.mailhost, self.mailport = mailhost else: self.mailhost, self.mailport = mailhost, None if isinstance(credentials, tuple): self.username, self.password = credentials else: self.username = None self.fromaddr = fromaddr if isinstance(toaddrs, basestring): toaddrs = [toaddrs] self.toaddrs = toaddrs self.subject = subject self.secure = secure self._timeout = 5.0 ...
from logging import handlers class S(handlers.SMTPHandler): def __init__(self, *args, **kwargs): super(self.__class__, self).__init__(*args, **kwargs) self._timeout = 10.0 class A: filename = 'file' lineno = 1 SMTP = handlers.SMTPHandler SMTP = S handler = SMTP(('localhost', 25), 'x@x', 'y@y', 'subj') handler.emit(A())
Отредактировано py.user.next (Апрель 13, 2015 01:36:33)
Офлайн
0
terabayt, py.user.next
Благодарю.
Буду искать обходные пути.
Главное, что я понял где сидит основная проблема.
Отредактировано Gam (Апрель 13, 2015 06:26:54)
Офлайн