import socket
import ssl

host = "en.wikipedia.org"
ctx = ssl._create_unverified_context()  # diagnostic only -- never use this to fetch real data

with socket.create_connection((host, 443), timeout=10) as sock:
    with ctx.wrap_socket(sock, server_hostname=host) as ssock:
        der_cert = ssock.getpeercert(binary_form=True)

print(ssl.DER_cert_to_PEM_cert(der_cert))  # decode this to inspect issuer and expiry