Method Name:
load_verify_locations
Method Signature:
load_verify_locations(cafile=None, capath=None, cadata=None)
Parameters:
cafile – File path for file containing the CA Certtificate(s)
capath – Path for the directory containing the CA Certtificate(s)
cadata – The certificate data in PEM or DER format.
Return Value:
None
Overview:
- The method load_verify_locations() of the SSLContext class loads a set of CA certificates used for verifying the certificate of the peer.
- The CA certificates are the certificates of Certifying Authorities. Usually, a Certifying Authority designates the work of issuing the certificates to a set of (sub-) authorities and each of such authorities again delegating to another (sub)set of authorities forming a CA chain.
- While validating a peer’s certificate, one or more certificates in the CA chain are validated by a host.
Example:
The client uses the TLS Server program from the Introduction to the SSLSocket class in Python.
| # Example Python program that uses SSLContext.load_verify_locations() # IP address and port number # SSLContext construction # Load a CA certificate. # Loading of client certificate which will be validated by the server # To make Python3.13 accept self-signed certificates # Streaming socket # Obtain SSLSocket instance - Does a TLS handshake # Print the loaded certificate statistics # Send a message to the server # Receive time from server print("Message received from the server") # Close the secure socket # Get rid of the original socket | 
Output - Client:
| Certificates currently loaded into the SSLContext | 
Output - Server:
| <class 'dict'> Client certificate(X.509): {'subject': ((('countryName', 'IN'),), (('stateOrProvinceName', 'KA'),), (('localityName', 'BLR'),), (('organizationName', 'DemoClientOrg'),), (('organizationalUnitName', 'DemoClientUnit'),), (('commonName', 'DemoClient'),), (('emailAddress', 'democlient@democlienttesting.com'),)), 'issuer': ((('countryName', 'IN'),), (('stateOrProvinceName', 'KA'),), (('localityName', 'BLR'),), (('organizationName', 'DemoCAOrg'),), (('organizationalUnitName', 'DemoCAUnit'),), (('commonName', 'localca'),), (('emailAddress', 'localca@localcatest.com'),)), 'version': 1, 'serialNumber': '01', 'notBefore': 'Sep 22 10:58:45 2025 GMT', 'notAfter': 'Sep 22 10:58:45 2026 GMT'} Received from client: b'Hello Server!' Securely sent 2025-10-13 21:34:36.937342 to ('127.0.0.1', 53032) |