ssl.get_server_certificate()
ssl.get_server_certificate() is a Python function in the SSL Module category. Fetches the SSL certificate from a server and returns it as PEM string. The syntax is ssl.get_server_certificate(addr, ssl_version=PROTOCOL_TLS, ca_certs=None). Returns: PEM certificate string. A typical example: cert = ssl.get_server_certificate(("example.com", 443))
print(cert) # PEM-encoded certificate. A close sibling is ssl.wrap_socket(), which wraps an existing socket for SSL/TLS encryption. A close sibling is ssl.create_default_context(), which creates a default SSL/TLS context with reasonable security settings. 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.wrap_socket(), ssl.create_default_context(), 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.get_server_certificate() immediately in the Python playground, look up unfamiliar terms in the glossary, or return to the Python Reference homepage.