0

Traceback (most recent call last): File "ssl-common.py", line 14, in s = ctx.wrap_socket(s, server_hostname=dst[0]) File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 363, in wrap_socket _context=self) File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 611, in init self.do_handshake() File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 840, in do_handshake self._sslobj.do_handshake() socket.error: [Errno 54] Connection reset by peer

I am getting the above errors when I try to run the below script on my Mac. I have reinstalled openssl through homebrew, as well as through pip

import socket
import ssl
import OpenSSL.crypto as crypto

dst = ('1.2.3.4',443)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
ret = s.connect_ex(dst)
if ret == 0 :
    ctx = ssl.create_default_context()
    ctx.check_hostname = False
    ctx.verify_mode = ssl.CERT_NONE
    s = ctx.wrap_socket(s, server_hostname=dst[0])

    # get certificate
    cert_bin = s.getpeercert(True)
    x509 = crypto.load_certificate(crypto.FILETYPE_ASN1,cert_bin)
    print(x509.get_subject().CN)
else :
    print "socket.connect_ex returned ", ret

1 Answer 1

0
[Errno 54] Connection reset by peer

It seems like a problem on where you want to connect. Check your connectivity by pinging and etc.

Please do check this out: What does "connection reset by peer" mean?

Sign up to request clarification or add additional context in comments.

1 Comment

I am trying to suppress the error for a site that isn't currently on right now (trying to loop through a bunch of IPs), but I get the above errors

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.