Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError("module 'ssl' has no attribute 'wrap_socket'") #208

Open
Grovespaz opened this issue Dec 9, 2024 · 1 comment
Open

AttributeError("module 'ssl' has no attribute 'wrap_socket'") #208

Grovespaz opened this issue Dec 9, 2024 · 1 comment

Comments

@Grovespaz
Copy link

Hello,

When running warcprox 2.6.1 under Python 3.21, trying to access https-protected urls through warcprox gives the following error:

2024-12-09 13:18:46,072 66069 ERROR MitmProxyHandler(tid=66699,started=2024-12-09T12:18:46.061680,client=127.0.0.1:39790) warcprox.warcprox.WarcProxyHandler.do_CONNECT(mitmproxy.py:402) problem handling 'CONNECT service.archief.nl:443 HTTP/1.1': AttributeError("module 'ssl' has no attribute 'wrap_socket'")

Apparently (quoting this StackOverflow post) the module-level ssl.wrap_socket() was marked as deprecated in Python 3.7 and fully removed in Python 3.12. One solution is to create a SSLContext using ssl.create_default_context() and use the context instance's .wrap_socket() method.

@Grovespaz
Copy link
Author

I don't know enough about the structure of the project to know whether this is the right (and best) solution, but as a workaround I've changed this code to look like this:

def _transition_to_ssl(self):
        certfile = self.server.ca.get_wildcard_cert(self.hostname)
        context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)

        # Load the certificate into the context
        context.load_cert_chain(certfile)

        self.request = self.connection = context.wrap_socket(
                self.connection, server_side=True)

And now it works for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant