wkeeling / selenium-wire

Extends Selenium's Python bindings to give you the ability to inspect requests made by the browser.
MIT License
1.9k stars 251 forks source link

Module 'OpenSSL.SSL' has no attribute 'SSLv2_METHOD' #596

Closed stanmertens closed 2 years ago

stanmertens commented 2 years ago

Hello,

I'm getting the following error. Running on Pyton 3.10.7, Selenium Wire 4.6.5 and pyOpenSSL 22.1.0. This log is from Heroku but I'm getting the same when running it locally. I've been using selenium-wire for over 2 years now and I never really had any issue that I couldn't fix. However on this one I'm completely stuck. Any help would be greatly appreciated.

Traceback (most recent call last):
File "/app/deploy/dynos/link_update_1.py", line 2, in <module>
from script.link_update.bot import update_continuous
File "/app/script/link_update/bot.py", line 3, in <module>
from automation.bot.method import run_get_price_func
File "/app/automation/bot/method.py", line 10, in <module>
from automation.bot.method_search import auto_search_ddg_url
File "/app/automation/bot/method_search.py", line 10, in <module>
from libs.webscraper.webscraper import WSNavigate
File "/app/libs/webscraper/webscraper.py", line 11, in <module>
from seleniumwire.webdriver import Chrome
File "/app/.heroku/python/lib/python3.10/site-packages/seleniumwire/webdriver.py", line 27, in <module>
from seleniumwire import backend, utils
File "/app/.heroku/python/lib/python3.10/site-packages/seleniumwire/backend.py", line 4, in <module>
from seleniumwire.server import MitmProxy
File "/app/.heroku/python/lib/python3.10/site-packages/seleniumwire/server.py", line 5, in <module>
from seleniumwire.handler import InterceptRequestHandler
File "/app/.heroku/python/lib/python3.10/site-packages/seleniumwire/handler.py", line 5, in <module>
from seleniumwire import har
File "/app/.heroku/python/lib/python3.10/site-packages/seleniumwire/har.py", line 11, in <module>
from seleniumwire.thirdparty.mitmproxy import connections
File "/app/.heroku/python/lib/python3.10/site-packages/seleniumwire/thirdparty/mitmproxy/connections.py", line 10, in <module>
from seleniumwire.thirdparty.mitmproxy.net import tls, tcp
File "/app/.heroku/python/lib/python3.10/site-packages/seleniumwire/thirdparty/mitmproxy/net/tls.py", line 43, in <module>
"SSLv2": (SSL.SSLv2_METHOD, BASIC_OPTIONS),
AttributeError: module 'OpenSSL.SSL' has no attribute 'SSLv2_METHOD'. Did you mean: 'SSLv23_METHOD'?

Update After forking and removing 4 lines it seems to work. However I'm not sure what I'm doing. Any help would still be appreciated. https://github.com/stan5079/selenium-wire/commit/645ce6a16ba7a4cf5ba396890125b5b3e3feb5b9

wkeeling commented 2 years ago

Thanks for raising this.

The issue appears to be caused by a new version of PyOpenSSL 22.1.0 that was released yesterday (September 25th). It looks like that version contains a backwards incompatible API change that breaks Selenium Wire.

I'll update Selenium Wire so that it doesn't depend on this version, but in the meantime you should hopefully be able to work around the problem by using version 22.0.0 of PyOpenSSL. You can explicitly install that into your environment with:

pip install pyopenssl==22.0.0
stanmertens commented 2 years ago

Perfect! Thank you @wkeeling.

LostInDarkMath commented 2 years ago

I'm also affected by this issue.

chrisgraham24 commented 2 years ago

Also impacted, trying fix above. ty!

wkeeling commented 2 years ago

A fix is included in the latest version of Selenium Wire - 5.0.0