前言

在使用时scrapy框架的shell工具时报错如下信息。

scrapy shell "https://hr.tencent.com/position.php?&start=0"
Traceback (most recent call last):
  File "/usr/local/bin/scrapy", line 7, in 
    from scrapy.cmdline import execute
  File "/usr/local/lib/python3.5/dist-packages/scrapy/cmdline.py", line 9, in 
    from scrapy.crawler import CrawlerProcess
  File "/usr/local/lib/python3.5/dist-packages/scrapy/crawler.py", line 7, in 
    from twisted.internet import reactor, defer
  File "/usr/local/lib/python3.5/dist-packages/twisted/internet/reactor.py", line 38, in 
    from twisted.internet import default
  File "/usr/local/lib/python3.5/dist-packages/twisted/internet/default.py", line 56, in 
    install = _getInstallFunction(platform)
  File "/usr/local/lib/python3.5/dist-packages/twisted/internet/default.py", line 44, in _getInstallFunction
    from twisted.internet.epollreactor import install
  File "/usr/local/lib/python3.5/dist-packages/twisted/internet/epollreactor.py", line 24, in 
    from twisted.internet import posixbase
  File "/usr/local/lib/python3.5/dist-packages/twisted/internet/posixbase.py", line 18, in 
    from twisted.internet import error, udp, tcp
  File "/usr/local/lib/python3.5/dist-packages/twisted/internet/tcp.py", line 31, in 
    from twisted.internet._newtls import (
  File "/usr/local/lib/python3.5/dist-packages/twisted/internet/_newtls.py", line 21, in 
    from twisted.protocols.tls import TLSMemoryBIOFactory, TLSMemoryBIOProtocol
  File "/usr/local/lib/python3.5/dist-packages/twisted/protocols/tls.py", line 41, in 
    from OpenSSL.SSL import Error, ZeroReturnError, WantReadError
  File "/usr/local/lib/python3.5/dist-packages/OpenSSL/__init__.py", line 8, in 
    from OpenSSL import rand, crypto, SSL
  File "/usr/local/lib/python3.5/dist-packages/OpenSSL/SSL.py", line 105, in 
    SSL_ST_INIT = _lib.SSL_ST_INIT
AttributeError: module 'lib' has no attribute 'SSL_ST_INIT'

解决方法

根据报错信息我们可以推论是Python3下的OpenSSL模块出错。
把之前的pyopenssl 卸载掉,重新安装:

sudo pip3 uninstall pyopenssl
sudo pip3 install pyopenssl

文章来源于互联网,如有雷同请联系站长删除:报错: AttributeError: module ‘lib’ has no attribute ‘SSL_ST_INIT’

发表评论