ssl.wrap_socket()
ssl.wrap_socket() is a Python function in the SSL Module category. Wraps an existing socket for SSL/TLS encryption. The syntax is ssl.wrap_socket(sock, keyfile=None, certfile=None, server_side=False, cert_reqs=ssl.CERT_NONE, ssl_version=PROTOCOL_TLS, ca_certs=None, do_handshake_on_connect=True, suppress_ragged_eofs=True, ciphers=None). Returns: SSL socket object. A typical example: import ssl
import socket
sock = socket.socket()
ssl_sock = ssl.wrap_socket(sock, ca_certs="/etc/ssl/certs/ca-certificates.crt")
ssl_sock.connect(("example.com", 443)). A close sibling is ssl.create_default_context(), which creates a default SSL/TLS context with reasonable security settings. A close sibling is ssl.get_server_certificate(), which fetches the SSL certificate from a server and returns it as PEM string. A close sibling is ssl.SSLContext(), which creates an SSL context for configuring SSL/TLS connections. More about this category: SSL/TLS wrapper — wrap_socket, get_server_certificate, create_default_context. Related SSL Module entries: ssl.create_default_context(), ssl.get_server_certificate(), ssl.SSLContext(). This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details. You can try ssl.wrap_socket() immediately in the Python playground, look up unfamiliar terms in the glossary, or return to the Python Reference homepage.