0

I need to get the certificate information from a URL that has a bad SSL certificate (wrong host).

I tried using below.

import ssl, socket

hostname = "wrong.host.badssl.com"

ctx = ssl.create_default_context()
with ctx.wrap_socket(socket.socket(), server_hostname=hostname) as s:
    s.connect((hostname, 443))
    cert = s.getpeercert()

cert

But, I keep getting this response.

SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for 'wrong.host.badssl.com'. (_ssl.c:1091)

Is there a way to bypass verification and still obtain the certificate information?

Dumindurr
  • 223
  • 1
  • 2
  • 8

0 Answers0