【问题标题】:Intermittent "getrandom() initialization failed" using scrapy spider使用scrapy spider间歇性“getrandom()初始化失败”
【发布时间】:2018-07-28 08:43:41
【问题描述】:

我构建了一个 scrapy 蜘蛛(scrapy 1.4)。这个蜘蛛是通过 django-rq 和 supervisord 从 django 网站按需触发的。

这是监听 django-rq 事件的 supervisord 作业(reddit 用作代理)

[program:rq_worker] 
command=python3 manage.py rqworker default 
directory=/var/www/django-app 
autostart=true 
autorestart=true 
stderr_logfile=/var/log/rq_worker.err.log 
stdout_logfile=/var/log/rq_worker.out.log

此设置运行良好。 但是,有时(我无法按需重现该问题),所有蜘蛛都会抛出相同的 OpenSSL 错误:

2018-02-11 11:02:19 [scrapy.core.scraper] ERROR: Error downloading <GET https://whateverwebsite.com>
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/twisted/internet/defer.py", line 1299, in _inlineCallbacks
    result = result.throwExceptionIntoGenerator(g)
  File "/usr/local/lib/python3.5/dist-packages/twisted/python/failure.py", line 393, in throwExceptionIntoGenerator
    return g.throw(self.type, self.value, self.tb)
  File "/usr/local/lib/python3.5/dist-packages/scrapy/core/downloader/middleware.py", line 43, in process_request
    defer.returnValue((yield download_func(request=request,spider=spider)))
twisted.web._newclient.ResponseNeverReceived: [<twisted.python.failure.Failure OpenSSL.SSL.Error: [('', 'osrandom_rand_bytes', 'getrandom() initialization failed.')]>]

重新启动 supervisord 会使问题消失。

为了确保我的网站及其蜘蛛程序正常运行,我必须在每次重新启动 supervisord 时测试是否没有问题。没什么大不了的,但仍然......

我想了解那里出了什么问题? 如何解决此问题?它与supervisord有关吗?扭曲相关? openSSL 相关?

感谢您的帮助

【问题讨论】:

标签: python openssl scrapy twisted supervisord


【解决方案1】:

我遇到了类似的错误,但使用了 python-requests 库:

Error([('', 'osrandom_rand_bytes', 'getrandom() initialization failed.')],)

这是由于随机数生成器未能及时收集足够的熵造成的。我已经安装了rng-tools,它解决了这个问题。

【讨论】:

  • 我在树莓派上遇到了这个确切的问题。食谱是什么?我刚刚安装了这个包,,它不见了!?
  • @eftshift0 是的,它对我有用(在树莓上也有)。
  • 这也有助于在启动后立即运行 SSL 相关代码的场景,得到上述错误。
猜你喜欢
  • 1970-01-01
  • 2013-08-01
  • 1970-01-01
  • 2019-04-18
  • 2011-10-21
  • 1970-01-01
  • 1970-01-01
  • 2012-11-29
  • 1970-01-01
相关资源
最近更新 更多