Python версия: 3.6.8
def ssl_expiry_datetime(hostname):
username =config.username
password = config.password
es = Elasticsearch([hostname], http_auth=(username, password))
ssl_date_fmt = r'%b %d %H:%M:%S %Y %Z'
context = ssl.create_default_context()
conn = context.wrap_socket(
socket.socket(socket.AF_INET),
server_hostname=hostname,
)
# 3 second timeout because Lambda has runtime limitations
conn.settimeout(3.0)
logger.debug('Connect to {}'.format(hostname))
conn.connect((hostname, 443))
ssl_info = conn.getpeercert()
# parse the string from the certificate into a Python datetime object
print (datetime.datetime.strptime(ssl_info['notAfter'], ssl_date_fmt))
ssl_expiry_datetime('clix-go.takeda.com')
Выполнение этого кода в Ubuntu Machine.