scrapy发送电子邮件时显示由于目标计算机积极拒绝,无法连接。

每次运行爬虫结果就是这样的。

2017-12-11 20:03:53 [scrapy.mail] ERROR: Unable to send mail: To=['asddf14@hotmail.com'] Cc=[] Subject="抓取了50页段子" Attachs=0- Connection was refused by other side: 10061: 由于目标计算机积极拒绝,无法连接。.

代码中是这么写的。

class BudejiePostgrePipeline(object):
    "将百思不得姐段子保存到PostgreSQL中"

    def __init__(self):
        self.connection = psycopg2.connect("dbname='test' user='postgres' password='12345678'")
        self.connection.autocommit = True
        # 设置邮件服务器,等到爬取足够数量时提醒我
        self.mailer = MailSender()

    def open_spider(self, spider):
        self.cursor = self.connection.cursor()

    def close_spider(self, spider):
        self.cursor.close()
        self.connection.close()
        body = '''
            抓取了50页百思不得姐的段子,请详细查看数据库
            
            此邮件由系统自动发送,请勿回复。
            '''
        self.mailer.send(to='asddf14@hotmail.com',
                         subject='抓取了50页段子',
                         body=body,
                         charset='utf-8')

    def process_item(self, item, spider):
        self.cursor.execute("INSERT INTO joke(author,content) VALUES(%s,%s)", (item['username'], item['content']))
        return item

配置文件中电子邮件是这么配置的。密码确认输入的是网易邮箱的客户端授权码,我尝试在Foxmail中可以正常发送,但是在代码中却不能。

MAIL_FROM = 'xx@126.com'
MAIL_HOST = 'smtp.126.com'
MAIL_PORT = 25
MAIL_USER = 'xx@126.com'
MAIL_PASS = 'xxxxx'
MAIL_TLS = False
MAIL_SSL = False
阅读 7.5k
4 个回答

看下自己计算机的防火墙关闭没有?

因为访问太频繁,被临时 BAN 了?

新手上路,请多包涵

问题解决了么,我也遇到同样的问题

新手上路,请多包涵
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题