J. Doe
J. Doe

Reputation: 111

Requests library - get TLS version used

When using the Python Requests library how can I determine which version of TLS was used?

Upvotes: 3

Views: 11734

Answers (2)

vekerdyb
vekerdyb

Reputation: 1263

According to this answer there is no way to get the socket information (which holds the TLS information as far as I understand) after a requests request is executed (unless it is a streaming request).

As Harry_pb points out, your SSL version and the server's TLS version determines the TLS version used in the connection.

The socket library docs shows how to get a socket's TLS version:

import socket
import ssl

hostname = 'www.python.org'
context = ssl.create_default_context()

with socket.create_connection((hostname, 443)) as sock:
    with context.wrap_socket(sock, server_hostname=hostname) as ssock:
        print(ssock.version())

Upvotes: 2

Hari_pb
Hari_pb

Reputation: 7416

You first need to determine SSL version to get TLS version. TLS stack will use the best version available automatically

import ssl
print ssl.OPENSSL_VERSION
'OpenSSL 1.0.1e-fips 11 Feb 2016'

Also, which version of TLS support you want depends on your SSL version.

Check this nice way to determine TLS version using python

Upvotes: 3

Related Questions