I know how to get certificate information such as expiration date using pyopenssl for instance, but is it possible to do it with a aiohttp response object?
I know how to get certificate information such as expiration date using pyopenssl for instance, but is it possible to do it with a aiohttp response object?
Previous answers are correct but, you could also use the socket lib (this is test with python 3.7)
from urllib.request import Request, urlopen, ssl, socket
from urllib.error import URLError, HTTPError
import json
#some site without http/https in the path
base_url = 'CHANGE_ME_TO_YOUR_SITE'
port = '443'
hostname = base_url
context = ssl.create_default_context()
with socket.create_connection((hostname, port)) as sock:
with context.wrap_socket(sock, server_hostname=hostname) as ssock:
print(ssock.version())
data = json.dumps(ssock.getpeercert())
# print(ssock.getpeercert())
print (data)