cert = ssl.get_server_certificate(('www.google.com', 443))
cert = ssl.PEM_cert_to_DER_cert(cert)
begin = cert.rfind('\x06\x03U\x04\x03') + 7
end = begin + ord(cert[begin - 1])
print(cert[begin:end])
Disable SSL certificate validation in Python