Scrapy:属性错误:模块'OpenSSL.SSL'

zzzyeukh  于 2022-11-09  发布在  其他
关注(0)|答案(2)|浏览(246)

我正在Window 10 OS上的pipenv虚拟环境中运行Scrapy
我代码:


# QuoteSpider.py

import scrapy

class QuoteSpider(scrapy.Spider):
    name = 'quotes'
    start_urls = [
        'http://quotes.toscrape.com/'
    ]

    def parse(self, response):
        title = response.css('title').get()
        yield {'titletext': title}

运行Scrapy后,我收到以下错误:

2022-09-26 19:44:35 [scrapy.utils.log] INFO: Scrapy 2.6.2 started (bot: quotetutorial)
2022-09-26 19:44:35 [scrapy.utils.log] INFO: Versions: lxml 4.9.1.0, libxml2 2.9.12, cssselect 1.1.0, parsel 1.6.0, w3lib 2.0.1, Twisted 22.8.0, Python 3.10.2 (tags/v3.10.2:a58ebcc, Jan 17 2022, 14:12:15) [MSC v.1929 64 bit (AMD64)], pyOpenSSL 22.1.0 (OpenSSL 3.0.5 5 Jul 2022), cryptography 38.0.1, Platform Windows-10-10.0.22000-SP0
2022-09-26 19:44:35 [scrapy.crawler] INFO: Overridden settings:
{'BOT_NAME': 'quotetutorial',
 'NEWSPIDER_MODULE': 'quotetutorial.spiders',
 'ROBOTSTXT_OBEY': True,
 'SPIDER_MODULES': ['quotetutorial.spiders']}
2022-09-26 19:44:35 [scrapy.utils.log] DEBUG: Using reactor: twisted.internet.selectreactor.SelectReactor
2022-09-26 19:44:35 [scrapy.extensions.telnet] INFO: Telnet Password: db575bc3af5b4b08
2022-09-26 19:44:35 [scrapy.middleware] INFO: Enabled extensions:
['scrapy.extensions.corestats.CoreStats',
 'scrapy.extensions.telnet.TelnetConsole',
 'scrapy.extensions.logstats.LogStats']
2022-09-26 19:44:35 [scrapy.core.downloader.handlers] ERROR: Loading "scrapy.cor

                                                                               ort_module\utils\misc.py", line 61, in load_objectline 49, in _load_handler      
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_importne 126, in import_module\utils\misc.py", line 61, in load_objectline 49, in _load_handler      
    return _bootstrap._gcd_import(name[level:], package, level)THOD' recommended
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_importne 126, in import_module\utils\misc.py", line 61, in load_objectline 49, in _load_handler      
    return _bootstrap._gcd_import(name[level:], package, level)THOD' recommended
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_importne 126, in import_module\utils\misc.py", line 61, in load_objectgs __init__sneCallbacks        
    return _bootstrap._gcd_import(name[level:], package, level)crawler)commended
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_importne 126, in impo
  File "C:\Users\Seraph776\.virtualenvs\BuildwithPython-3cHuoDPB\lib\site-packag
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_loadodule       
Traceback (most recent call last):ap>", line 241, in _call_with_frames_removed  
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked   

  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked            ort_module\utils\misc.py", line 61, in load_objectgs __init__sdule>>
    return _bootstrap._gcd_import(name[level:], package, level)crawler)ETHOD'   
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_importne 126, in impBuildwithPython\quotetutorial>.py", line 23, in <module>in <module>>
AttributeError: module 'OpenSSL.SSL' has no attribute 'SSLv3_METHOD' recommended

我已经阅读了其他几个与此问题相关的responses;都不起作用。这就是为什么我再问一次。我也试过以下方法,但没有运气:
1.卸载和安装pyopenssl
1.正在升级pyopenssl

pip install pyOpenSSL~=22.1.0

1.正在升级requests

pip install pyOpenSSL~=2.28.1

谢谢你的帮助

qmelpv7a

qmelpv7a1#

我也遇到了同样的问题。我降级到了pyOpenSSL==22.0.0,现在我又回来了。我怀疑这是一个兼容性问题,Scrapy会赶上的。

t1qtbnec

t1qtbnec2#

我也尝试了上面的步骤-无济于事-这终于修复了它:其中一个错误指向Scrapys“tls.py“,您可以在其中找到以下代码:

openssl_methods = {
    METHOD_TLS: SSL.SSLv23_METHOD,                      # protocol negotiation (recommended)
    # METHOD_SSLv3: SSL.SSLv3_METHOD,                     # SSL 3 (NOT recommended)
    METHOD_TLSv10: SSL.TLSv1_METHOD,                    # TLS 1.0 only
    METHOD_TLSv11: getattr(SSL, 'TLSv1_1_METHOD', 5),   # TLS 1.1 only
    METHOD_TLSv12: getattr(SSL, 'TLSv1_2_METHOD', 6),   # TLS 1.2 only
}

我注解掉了包含“METHOD_SSLv3”的行,现在它又可以工作了。

相关问题