Fixing SSL Certificate Errors in Supervisely
In this tutorial you will learn how to fix errors with SSL certificate
Introduction
SSL certificate errors can occur when you're working with the Supervisely SDK and the server uses a self-signed certificate.
In such cases, your code may not have the necessary certificate chain to validate the certificate provided by the server. This tutorial will guide you through the steps to resolve this issue by adding the certificate chain to the trusted store of your HTTP client.
Files for tutorial can be found in our GitHub repository here.
Note: Disabling SSL checks is not recommended for security reasons, so it's best to add the certificate chain.
Options to Fix SSL Certificate Errors
Option 1: Supervisely SDK (Recommended)
Requires Supervisely SDK v6.72.139
Step 1. Create .env file with SLY_EXTRA_CA_CERTS variable
Create a .env
file in the same directory as your code and add the following line to it:
In our example it's local.env
file.
Step 2. Test Your Connection
After creating a .env
file with SLY_EXTRA_CA_CERTS
variable, test your connection to the Supervisely server using the SDK. Supervisely SDK will automatically add your certificate to the bundle. If you've set the environment variables correctly, you will see this message in the terminal:
Option 2: CLI
Note: Supervisely SDK uses HTTP client library requests
. If you are using a different HTTP client, please refer to its documentation for instructions on how to add a certificate chain.
Step 1. Locate the Certificate Bundle
If you already have a working certificate bundle on your machine, it is often found in /etc/ssl/certs/ca-certificates.crt
on Linux systems.
You can use this bundle directly or concatenate the certificate chain with it to create a new bundle.
Step 2. Concatenate the Certificate Chain (if needed)
If you need to create a new bundle, first obtain the certificate chain.
Concatenate the certificate chain and the ca-certificates file into a new bundle file using a text editor or command line tools. For example, you can use the cat
command on Linux:
Step 3. Set the REQUESTS_CA_BUNDLE Environment Variable
To pass the certificate bundle to the Supervisely SDK (which uses the Requests library under the hood), set the REQUESTS_CA_BUNDLE
environment variable to the path of your new bundle.
Step 4. Test Your Connection
After setting the environment variables, test your connection to the Supervisely server using the SDK. Your code should now be able to validate the server's self-signed certificate.
Note: if you're using urllib
, either directly or indirectly (pytorch
or some other library), don't forget to set SSL_CERT_FILE
environment variable.
Last updated