【问题标题】:Scrapy: connection refusedScrapy:连接被拒绝
【发布时间】:2011-06-28 06:00:06
【问题描述】:

我在尝试测试 scrapy 安装时收到错误消息:

$ scrapy shell http://www.google.es
j2011-02-16 10:54:46+0100 [scrapy] INFO: Scrapy 0.12.0.2536 started (bot: scrapybot)
2011-02-16 10:54:46+0100 [scrapy] DEBUG: Enabled extensions: TelnetConsole, SpiderContext, WebService, CoreStats, MemoryUsage, CloseSpider
2011-02-16 10:54:46+0100 [scrapy] DEBUG: Enabled scheduler middlewares: DuplicatesFilterMiddleware
2011-02-16 10:54:46+0100 [scrapy] DEBUG: Enabled downloader middlewares: HttpAuthMiddleware, DownloadTimeoutMiddleware, UserAgentMiddleware, RetryMiddleware, DefaultHeadersMiddleware, RedirectMiddleware, CookiesMiddleware, HttpProxyMiddleware, HttpCompressionMiddleware, DownloaderStats
2011-02-16 10:54:46+0100 [scrapy] DEBUG: Enabled spider middlewares: HttpErrorMiddleware, OffsiteMiddleware, RefererMiddleware, UrlLengthMiddleware, DepthMiddleware
2011-02-16 10:54:46+0100 [scrapy] DEBUG: Enabled item pipelines: 
2011-02-16 10:54:46+0100 [scrapy] DEBUG: Telnet console listening on 0.0.0.0:6023
2011-02-16 10:54:46+0100 [scrapy] DEBUG: Web service listening on 0.0.0.0:6080
2011-02-16 10:54:46+0100 [default] INFO: Spider opened
2011-02-16 10:54:47+0100 [default] DEBUG: Retrying <GET http://www.google.es> (failed 1 times): Connection was refused by other side: 111: Connection refused.
2011-02-16 10:54:47+0100 [default] DEBUG: Retrying <GET http://www.google.es> (failed 2 times): Connection was refused by other side: 111: Connection refused.
2011-02-16 10:54:47+0100 [default] DEBUG: Discarding <GET http://www.google.es> (failed 3 times): Connection was refused by other side: 111: Connection refused.
2011-02-16 10:54:47+0100 [default] ERROR: Error downloading <http://www.google.es>: [Failure instance: Traceback (failure with no frames): <class 'twisted.internet.error.ConnectionRefusedError'>: Connection was refused by other side: 111: Connection refused.
    ]
2011-02-16 10:54:47+0100 [scrapy] ERROR: Shell error
    Traceback (most recent call last):
    Failure: scrapy.exceptions.IgnoreRequest: Connection was refused by other side: 111: Connection refused.

2011-02-16 10:54:47+0100 [default] INFO: Closing spider (shutdown)
2011-02-16 10:54:47+0100 [default] INFO: Spider closed (shutdown)

版本:

  • Scrapy 0.12.0.2536
  • Python 2.6.6
  • 操作系统:Ubuntu 10.10

编辑:我可以使用我的浏览器、wget、telnet google.es 80 访问它,并且所有网站都会发生这种情况。

【问题讨论】:

  • 有什么解决办法吗?在尝试将 privoxy 代理与 scrapy 一起使用时,我也遇到了这种情况......

标签: python web-scraping scrapy


【解决方案1】:

任务 1: Scrapy 将发送一个带有“bot”的用户代理。网站也可能基于用户代理进行屏蔽。

尝试覆盖 settings.py 中的 USER_AGENT

例如:USER_AGENT = 'Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20100101 Firefox/7.7'

任务 2: 尝试在请求之间设置延迟,以欺骗人类正在发送请求。

DOWNLOAD_DELAY = 0.25 

任务 3: 如果没有任何效果,请安装wireshark 并查看请求标头(或)发布数据的差异 当 scrapy 发送时和浏览器发送时。

【讨论】:

    【解决方案2】:

    您的网络连接可能有问题。

    首先,检查您的互联网连接。

    如果你通过代理服务器访问网络,你应该在你的scrapy项目中添加一段代码(http://doc.scrapy.org/en/latest/topics/downloader-middleware.html#scrapy.contrib.downloadermiddleware.httpproxy.HttpProxyMiddleware

    无论如何,尝试升级你的scrapy版本。

    【讨论】:

      【解决方案3】:

      我也遇到了这个错误。原来是我访问的端口被防火墙阻止了。我的服务器默认阻止端口,除非它被列入白名单。

      【讨论】:

      • 您是如何发现您的服务器阻塞了未列入白名单的端口的?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-08-08
      • 2017-12-15
      • 2017-10-31
      • 1970-01-01
      • 2023-03-21
      • 1970-01-01
      • 2019-03-22
      相关资源
      最近更新 更多