Getting Certificates For HTTPS Requests

Dan | Oct 30, 2020 min read

Many websites use HTTPS to encrypt communication between your computer and their servers. Your browser will execute this automatically so you never see it happen. The only indicator is the icon depicting a lock next to the URL in the address bar.

This presents an issue when you would like to make a programmatic request to their servers. We need that same certificate to access this website. Without the certificate chain, the request will fail. The following script will return an error the script does not have the proper certificates to communicate with the server over HTTPS.

import requests

requests.get('https://odyssey.gwinnettcourts.com/Portal/')

To get the certifcate chain (in Chrome): 1. Click on the lock icon next to the address bar. 2. Click “Certificates”. 3. Click “Details”. 4. Click “Export…”. 5. Save the file to your local computer. Make sure you select “Base64-encoded ASCII, certificate chain” as the format. Otherwise you will not have the appropriate chain of certificates to make the request properly.

After downloading the certificate, you add the path to the certificate file to your request and the request will execute properly. In some cases, this will not solve your connection issue, but it will address many of them.

import requests

cert = '/path/to/my_certificate_chain.crt'
requests.get('https://odyssey.gwinnettcourts.com/Portal/',verify=cert)