Compression() method of sslsocket class in Python

Method Name:

compression

Method Signature:

compression()

Return Value:

  • A python string specifying the compression method used.
  • If no compression is used the method returns None.

Overview:

  • The method compression() returns the compression method used in the secure communication if any.

Example:

import socket

import ssl

import platform

 

# Context

ctx               = ssl.SSLContext();

ctx.verify_mode   = ssl.CERT_REQUIRED;

 

# Check for OS X platform

if platform.system().lower() == 'darwin':

    import certifi

    import os

 

    # Load CA certificates used for validating the peer's certificate

    ctx.load_verify_locations(

        cafile=os.path.relpath(certifi.where()),

        capath=None,

        cadata=None);

 

# Connect to the server through an instance of an SSLSocket class

skt   = socket.socket();

sec_skt  = ctx.wrap_socket(skt);

 

# Make a connection to the server

sec_skt.connect(("example.com", 443));

comp = sec_skt.compression();

print("Compression used:");

print(comp);

 

 

Output:

Compression used:

None

 


Copyright 2024 © pythontic.com