Home > Software design >  AttributeError: module 'OpenSSL.SSL' has no attribute 'SSLv3_METHOD'
AttributeError: module 'OpenSSL.SSL' has no attribute 'SSLv3_METHOD'

Time:09-27

After running the scrapy shell with the defined url, I am getting the attribute error showing the following error: AttributeError: module 'OpenSSL.SSL' has no attribute 'SSLv3_METHOD'

scrapy shell "https://quotes.toscrape.com/tag/humor/"

Can anyone please help me solving the error?

2022-09-27 01:38:38 [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.9.2 (tags/v3.9.2:1a79785, Feb 19 2021, 13:44:55) [MSC v.1928 64 bit (AMD64)], pyOpenSSL 22.1.0 (OpenSSL 3.0.5 5 Jul 2022), cryptography 38.0.1, Platform Windows-10-10.0.19041-SP0
2022-09-27 01:38:38 [scrapy.crawler] INFO: Overridden settings:
{'DUPEFILTER_CLASS': 'scrapy.dupefilters.BaseDupeFilter',
 'LOGSTATS_INTERVAL': 0}
2022-09-27 01:38:38 [scrapy.utils.log] DEBUG: Using reactor: twisted.internet.selectreactor.SelectReactor
2022-09-27 01:38:38 [scrapy.extensions.telnet] INFO: Telnet Password: d760ab2d8573ec57
2022-09-27 01:38:38 [scrapy.middleware] INFO: Enabled extensions:
['scrapy.extensions.corestats.CoreStats',
 'scrapy.extensions.telnet.TelnetConsole']
2022-09-27 01:38:39 [scrapy.core.downloader.handlers] ERROR: Loading "scrapy.core.downloader.handlers.http.HTTPDownloadHandler" for scheme "http"
Traceback (most recent call last):
  File "d:\python\scraping-project\scrapy\venv\lib\site-packages\scrapy\core\downloader\handlers\__init__.py", line 49, in _load_handler
    dhcls = load_object(path)
  File "d:\python\scraping-project\scrapy\venv\lib\site-packages\scrapy\utils\misc.py", line 61, in load_object
    mod = import_module(module)
  File "C:\Users\DELL\AppData\Local\Programs\Python\Python39\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 790, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "d:\python\scraping-project\scrapy\venv\lib\site-packages\scrapy\core\downloader\handlers\http.py", line 2, in <module>
    from scrapy.core.downloader.handlers.http11 import (
  File "d:\python\scraping-project\scrapy\venv\lib\site-packages\scrapy\core\downloader\handlers\http11.py", line 23, in <module>
    from scrapy.core.downloader.contextfactory import load_context_factory_from_settings
  File "d:\python\scraping-project\scrapy\venv\lib\site-packages\scrapy\core\downloader\contextfactory.py", line 11, in <module>
    from scrapy.core.downloader.tls import DEFAULT_CIPHERS, openssl_methods, ScrapyClientTLSOptions
  File "d:\python\scraping-project\scrapy\venv\lib\site-packages\scrapy\core\downloader\tls.py", line 23, in <module>
    METHOD_SSLv3: SSL.SSLv3_METHOD,                     # SSL 3 (NOT recommended)
AttributeError: module 'OpenSSL.SSL' has no attribute 'SSLv3_METHOD'

CodePudding user response:

In scrapy framework meaning in scrapy spider it's working fine without any issues.

Example:

from scrapy.utils.response import open_in_browser
import scrapy
class TestSpider(scrapy.Spider):
    name = 'tes'
    start_urls = ['https://quotes.toscrape.com/tag/humor/']
    

    def parse(self, response):
        #open_in_browser(response)

        for card in response.xpath('//*[@]'):
            yield {'Title':card.xpath('.//*[@]/text()').get()}

Output:

{'Title': '“The person, be it gentleman or lady, who has not pleasure in a good novel, must be intolerably stupid.”'}
2022-09-27 02:08:06 [scrapy.core.scraper] DEBUG: Scraped from <200 https://quotes.toscrape.com/tag/humor/>
{'Title': '“A day without sunshine is like, you know, night.”'}
2022-09-27 02:08:06 [scrapy.core.scraper] DEBUG: Scraped from <200 https://quotes.toscrape.com/tag/humor/>
{'Title': '“Anyone who thinks sitting in church can make you a Christian must also think that sitting in a garage can make you a car.”'}
2022-09-27 02:08:06 [scrapy.core.scraper] DEBUG: Scraped from <200 https://quotes.toscrape.com/tag/humor/>
{'Title': '“Beauty is in the eye of the beholder and it may be necessary from time to time to give a stupid or misinformed beholder a black eye.”'}
2022-09-27 02:08:06 [scrapy.core.scraper] DEBUG: Scraped from <200 https://quotes.toscrape.com/tag/humor/>
{'Title': "“All you need is love. But a little chocolate now and then doesn't hurt.”"}
2022-09-27 02:08:06 [scrapy.core.scraper] DEBUG: Scraped from <200 https://quotes.toscrape.com/tag/humor/>
{'Title': "“Remember, we're madly in love, so it's all right to kiss me anytime you feel like it.”"}
2022-09-27 02:08:06 [scrapy.core.scraper] DEBUG: Scraped from <200 https://quotes.toscrape.com/tag/humor/>
{'Title': '“Some people never go crazy. What truly horrible lives they must lead.”'}
2022-09-27 02:08:06 [scrapy.core.scraper] DEBUG: Scraped from <200 https://quotes.toscrape.com/tag/humor/>
{'Title': '“The trouble with having an open mind, of course, is that people will insist on coming along and trying to put things in it.”'}
2022-09-27 02:08:06 [scrapy.core.scraper] DEBUG: Scraped from <200 https://quotes.toscrape.com/tag/humor/>
{'Title': '“Think left and think right and think low and think high. Oh, the thinks you can think up if only you try!”'}
2022-09-27 02:08:06 [scrapy.core.scraper] DEBUG: Scraped from <200 https://quotes.toscrape.com/tag/humor/>
{'Title': '“The reason I talk to myself is because I’m the only one whose answers I accept.”'}
2022-09-27 02:08:06 [scrapy.core.engine] INFO: Closing spider (finished)
2022-09-27 02:08:06 [scrapy.statscollectors] INFO: Dumping Scrapy stats:
{'downloader/request_bytes': 309,
 'downloader/request_count': 1,
 'downloader/request_method_count/GET': 1,
 'downloader/response_bytes': 10853,
 'downloader/response_count': 1,
 'downloader/response_status_count/200': 1,
 'elapsed_time_seconds': 1.740613,
 'finish_reason': 'finished',
 'finish_time': datetime.datetime(2022, 9, 26, 20, 8, 6, 383826),
 'item_scraped_count': 10,

CodePudding user response:

I think this is due to an update of cryptography through PyOpenSSL -- I've logged an issue with Scrapy (https://github.com/scrapy/scrapy/issues/5638) but the workaround that worked for me was to downgrade cryptography:

pip install "cryptography<38"
  • Related