Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/354.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 类型错误:';非类型';对象不可编辑:smtplib_Python_Smtp_Smtplib - Fatal编程技术网

Python 类型错误:';非类型';对象不可编辑:smtplib

Python 类型错误:';非类型';对象不可编辑:smtplib,python,smtp,smtplib,Python,Smtp,Smtplib,我正在尝试构建我自己的smtplib。我得到了TypeError:“NoneType”对象在我尝试时不适用 (代码,resp)=自身数据(msg) self.data()定义为- 我正在使用self.data()将消息放入服务器 def sendmail(self, from_addr, to_addrs, msg='hello', mail_options=[],rcpt_options=[]): self.ehlo_or_helo_if_needed()

我正在尝试构建我自己的smtplib。我得到了TypeError:“NoneType”对象在我尝试时不适用
(代码,resp)=自身数据(msg)

self.data()定义为- 我正在使用self.data()将消息放入服务器

    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

我们无法从代码中看出您发布的
self.data()
正在做什么,但从您的错误中可以清楚地看出,它返回的是
None
。如果尝试不解包,则会得到以下结果:

    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)

如果得到代码354,则注释掉了
raise
,函数现在返回None。这也可能是问题所在。

self.data里面是什么?我猜self.data是一个方法,它缺少一个return语句。但这只是一个猜测。。。
>>> (code, resp) = None
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not iterable
if code != 354:
            #raise SMTPDataError(code, repl)
            print "Err"
else:
    ...