TypeError: L'oggetto "NoneType" non è idiota: SMTplib
Domanda
def sendmail(self, from_addr, to_addrs, msg='hello', mail_options=[],rcpt_options=[]):
self.ehlo_or_helo_if_needed()
esmtp_opts = []
if self.does_esmtp:
# Hmmm? what's this? -ddm
# self.esmtp_features['7bit']=""
if self.has_extn('size'):
esmtp_opts.append("size=%d" % len(msg))
for option in mail_options:
esmtp_opts.append(option)
(code, resp) = self.mail(from_addr, esmtp_opts)
if code != 250:
self.rset()
#raise SMTPSenderRefused(code, resp, from_addr)
senderrs = {}
if isinstance(to_addrs, basestring):
to_addrs = [to_addrs]
for each in to_addrs:
(code, resp) = self.rcpt(each, rcpt_options)
if (code != 250) and (code != 251):
senderrs[each] = (code, resp)
if len(senderrs) == len(to_addrs):
# the server refused all our recipients
self.rset()
#raise SMTPRecipientsRefused(senderrs)
(code, resp) = self.data(msg)
if code != 250:
self.rset()
#raise SMTPDataError(code, resp)
#if we got here then somebody got our mail
return senderrs
.
Sto cercando di costruire il mio smtplib.o sto ottenendo Typeerror: l'oggetto "NoneType" non è idiota quando provo (codice, resp)= self.data (msg)
self.data () è definito come Sto usando self.Data () per inserire il messaggio al server.
def data(self, msg):
self.putcmd("data")
(code, repl) = self.getreply()
if self.debuglevel > 0:
print>>stderr, "data:", (code, repl)
if code != 354:
#raise SMTPDataError(code, repl)
print "Err"
else:
q = quotedata(msg)
if q[-2:] != CRLF:
q = q + CRLF
q = q + "." + CRLF
self.send(q)
(code, msg) = self.getreply()
if self.debuglevel > 0:
print>>stderr, "data:", (code, msg)
return (code, msg)
. Soluzione
Non possiamo dire dal codice che hai pubblicato ciò che sta facendo self.data()
, ma è chiaro dal tuo errore che sta restituendo None
.Se provi a disimballare nessuno, ottieni questo:
>>> (code, resp) = None
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not iterable
.
Pubblicazione del codice per self.data()
potrebbe aiutare.
Aggiorna dopo il codice extra pubblicato:
Il codice (code, repl) = self.getreply()
potrebbe anche disimballaggio None
[Nota: ci sono due istanze di questo in self.data()
TagCode].L'eccezione è stata sollevata in self.data()
o in sendmail()
?
anche
.
if code != 354:
#raise SMTPDataError(code, repl)
print "Err"
else:
...
Se ottieni il codice 354, hai commentato il raise
e la funzione ora non restituisce nessuno.Questo potrebbe anche essere il problema.