Connecting to a Postgres Database over SSL using Sockets in Python

I am trying to connect to a Postgres Database using sockets to enforce a particular TLS version from the client in order to verify that the Database does not accept connections from the client which uses an older version of TLS like tlsv1.1. The connection is failing on handshake with the following error :


Traceback (most recent call last): File "", line 12, in ssl_version=ssl.PROTOCOL_TLSv1_2) File "<>/python3.6/lib/python3.6/", line 1232, in get_server_certificate with context.wrap_socket(sock) as sslsock: File "<>/python3.6/lib/python3.6/", line 407, in wrap_socket _context=self, _session=session) File "<>/python3.6/lib/python3.6/", line 817, in init self.do_handshake() File "<>/python3.6/lib/python3.6/", line 1077, in do_handshake self._sslobj.do_handshake() File "<>/python3.6/lib/python3.6/", line 689, in do_handshake self._sslobj.do_handshake() ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:852)

The following is a snippet of the code:

    import socket     import ssl          hostname = <DB_Endpoint>     context = ssl.create_default_context()          with socket.create_connection((hostname, 8200)) as sock:         with context.wrap_socket(sock, server_hostname=hostname) as ssock:             print(ssock.version())      

PS: I am just trying to figure out a way to test if the Postgres Server rejects a connection from a client which only has