Joshua,
I was able to run this in the Pro python window, but had to add ( ) around the print string. Based on things I've read on one of Dan's /blogs/dan_patterson/2016/05/09/the-links?sr=search&searchId=a1012d53-da1f-4df7-b109-573165a00e62&se... blogs, that is a requirement for the 3.x python flavors.
So, yours is the correct answer, but here it is with the change
import ssl, socket
hostname = 'geonet.esri.com'
ctx = ssl.create_default_context()
s = ctx.wrap_socket(socket.socket(), server_hostname=hostname)
s.connect((hostname, 443))
cert = s.getpeercert()
props = []
props.append(('Valid from', cert['notBefore']))
props.append(('Valid to', cert['notAfter']))
props.append(('Serial number', cert['serialNumber']))
for name,value in props:
print ("{:<20}{}".format(name, value))
I was able to successfully run this against my own hostname. thanks.