How to get ssl certificate data using python

I am using the following code to check the status of an ssl certificate. Can we get more detailed information about the certificate, such as common name (CN), expiration date and issuer, using the request module or urllib

import requests

def check_ssl(url):
    try:
        req = requests.get(url, verify=True)
        print url + ' has a valid SSL certificate!'
    except requests.exceptions.SSLError:
        print url + ' has INVALID SSL certificate!'

check_ssl('https://google.com')
check_ssl('https://example.com')
+4
source share

Source: https://habr.com/ru/post/1666643/


All Articles