账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    scrapy发送电子邮件时显示由于目标计算机积极拒绝,无法连接。
    79
    0

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

    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
    2
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 夜梦明午 普通会员 1楼
      502 Bad Gateway

      502 Bad Gateway


      nginx
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部