Getting the SSL certificate in Python ends with a SSL: SSLV3_ALERT_HANDSHAKE_FAILURE error


Trying to get the SSL certificate through Python 3.8.10 fails with the following command:

python3 -c "import ssl; ssl.get_server_certificate(('', 443))"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.8/", line 1484, in get_server_certificate
    with context.wrap_socket(sock) as sslsock:
  File "/usr/lib/python3.8/", line 500, in wrap_socket
    return self.sslsocket_class._create(
  File "/usr/lib/python3.8/", line 1040, in _create
  File "/usr/lib/python3.8/", line 1309, in do_handshake
ssl.SSLError: [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:1131)

python3 --version
Python 3.8.10

This means that getting the SSL certificate programmatically in Python is not straight-forward, which can be undesirable.

Any ideas on how to solve this issue?