Home > other >  Scrapy: AttributeError: module 'OpenSSL.SSL'
Scrapy: AttributeError: module 'OpenSSL.SSL'

Time:10-03

I'm running Scrapy in pipenv virtual environment on Window 10 OS.

my code:

# 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}

After running Scrapy, I received the following error:

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

I have read a few other responses related to this issue; none of them work. That is why I am asking again. I have also tried the follwing with no luck:

  1. Uninstalling and install pyopenssl
  2. Upgrading pyopenssl
pip install pyOpenSSL~=22.1.0
  1. Upgrading requests
pip install pyOpenSSL~=2.28.1

Thanks for any help

CodePudding user response:

Was having the same problem. I downgraded to pyOpenSSL==22.0.0 and now I'm back in business. I suspect it's a compatibility issue that scrapy will catch up to.

CodePudding user response:

I also tried the above steps - to no avail - and this finally fixed it: Among the errors was one pointing to Scrapys "tls.py". There you find the following code:

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
}

I commented the line containing "METHOD_SSLv3" out and now its working again.

  • Related