Is there a public example certificate with an expiry date above 2050 which I could fetch in order to test a script?
I would use
conn = ssl.create_default_context().wrap_socket(socket.socket(socket.AF_INET), server_hostname=hostname)
conn.connect((hostname, 443))
cert = conn.getpeercert()
print(cert['notAfter'])
to test it.