簡體   English   中英

scrapy發送郵件出現錯誤:無法發送郵件。 “模塊”類型的對象沒有len()

[英]scrapy sending mail got an ERROR: Unable to send mail. object of type 'module' has no len()

我想在蜘蛛關閉時發送電子郵件,代碼如下:

def close(spider, reason):
    # mailer = MailSender.from_settings(self.settings)
    from scrapy.mail import MailSender
    mailer = MailSender(
        smtphost="smtp.163.com", 
        mailfrom="rhys***@163.com",             
        smtpuser="rhys***g@163.com", 
        smtppass="***",  
        smtpport=25 
    )
    body = u"""
            content
            """
    subject = u'title'

    mailer.send(to=["rhys***@qq.com"],
                subject=subject.encode("utf-8"),
                body=body.encode("utf-8"),
                cc=['12202012**@qq.com'])

但是我遇到了這樣的錯誤:

[twisted] CRITICAL: Unhandled Error
Traceback (most recent call last):                                        
  File "/home/rhys/.pyenv/versions/2.7.5/envs/p2spider/lib/python2.7/site-
packages/twisted/python/log.py", line 103, in callWithLogger              
    return callWithContext({"system": lp}, func, *args, **kw)             
  File "/home/rhys/.pyenv/versions/2.7.5/envs/p2spider/lib/python2.7/site-
packages/twisted/python/log.py", line 86, in callWithContext              
    return context.call({ILogContext: newCtx}, func, *args, **kw)         
  File "/home/rhys/.pyenv/versions/2.7.5/envs/p2spider/lib/python2.7/site-
packages/twisted/python/context.py", line 122, in callWithContext         
    return self.currentContext().callWithContext(ctx, func, *args, **kw)  
  File "/home/rhys/.pyenv/versions/2.7.5/envs/p2spider/lib/python2.7/site-
packages/twisted/python/context.py", line 85, in callWithContext          
    return func(*args,**kw)                                               
--- <exception caught here> ---                                           
  File "/home/rhys/.pyenv/versions/2.7.5/envs/p2spider/lib/python2.7/site-
packages/twisted/internet/posixbase.py", line 597, in _doReadOrWrite      
    why = selectable.doRead()                                             
  File "/home/rhys/.pyenv/versions/2.7.5/envs/p2spider/lib/python2.7/site-
packages/twisted/internet/tcp.py", line 208, in doRead                    
    return self._dataReceived(data)                                       
  File "/home/rhys/.pyenv/versions/2.7.5/envs/p2spider/lib/python2.7/site-
packages/twisted/internet/tcp.py", line 214, in _dataReceived 
packages/twisted/internet/tcp.py", line 214, in _dataReceived             
    rval = self.protocol.dataReceived(data)
  File "/home/rhys/.pyenv/versions/2.7.5/envs/p2spider/lib/python2.7/site-
packages/twisted/protocols/tls.py", line 330, in dataReceived
    self._flushReceiveBIO()
  File "/home/rhys/.pyenv/versions/2.7.5/envs/p2spider/lib/python2.7/site-
packages/twisted/protocols/tls.py", line 295, in _flushReceiveBIO
    ProtocolWrapper.dataReceived(self, bytes)
  File "/home/rhys/.pyenv/versions/2.7.5/envs/p2spider/lib/python2.7/site-
packages/twisted/protocols/policies.py", line 120, in dataReceived
    self.wrappedProtocol.dataReceived(data)
  File "/home/rhys/.pyenv/versions/2.7.5/envs/p2spider/lib/python2.7/site-
packages/twisted/protocols/basic.py", line 571, in dataReceived
    why = self.lineReceived(line)
  File "/home/rhys/.pyenv/versions/2.7.5/envs/p2spider/lib/python2.7/site-
packages/twisted/mail/smtp.py", line 995, in lineReceived
    why = self._okresponse(self.code, b'\n'.join(self.resp))
  File "/home/rhys/.pyenv/versions/2.7.5/envs/p2spider/lib/python2.7/site-
packages/twisted/mail/smtp.py", line 1044, in smtpState_to
    return self.smtpState_toOrData(0, b'')
  File "/home/rhys/.pyenv/versions/2.7.5/envs/p2spider/lib/python2.7/site-
packages/twisted/mail/smtp.py", line 1062, in smtpState_toOrData
    self.sendLine(b'RCPT TO:' + quoteaddr(self.lastAddress))
  File "/home/rhys/.pyenv/versions/2.7.5/envs/p2spider/lib/python2.7/site-
packages/twisted/mail/smtp.py", line 179, in quoteaddr
    res = email.utils.parseaddr(addr)
  File "/home/rhys/.pyenv/versions/2.7.5/lib/python2.7/email/utils.py", li
ne 215, in parseaddr
    addrs = _AddressList(addr).addresslist
  File "/home/rhys/.pyenv/versions/2.7.5/lib/python2.7/email/_parseaddr.py
", line 457, in __init__
    self.addresslist = self.getaddrlist()
  File "/home/rhys/.pyenv/versions/2.7.5/lib/python2.7/email/_parseaddr.py
", line 217, in getaddrlist
    while self.pos < len(self.field):
exceptions.TypeError: object of type 'module' has no len()

有人可以解釋為什么嗎? 我使用python2.7和scapy1.4。 如果我評論上面提到的代碼,一切都很好,謝謝

我碰到扭曲的17.9,問題消失了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM