Unable To Get Local Issuer Certificate

The "Unable to Get Local Issuer Certificate" error is a common issue that occurs when making secure connections, particularly in applications that use SSL/TLS. This error typically arises due to misconfigured certificate authorities (CAs) or missing root certificates. It can affect developers using tools like cURL, Python requests, Node.js, and Git, preventing secure HTTPS connections.

In this guide, we’ll explain why this error occurs and provide step-by-step solutions to resolve it.

What Causes the “Unable to Get Local Issuer Certificate” Error?

Several factors can trigger this error:

  1. Missing or Outdated CA Certificates – The system lacks the necessary root certificates to verify the authenticity of the SSL/TLS certificate.
  2. Misconfigured SSL Settings – Applications may not be correctly configured to use the system’s certificate store.
  3. Expired Certificates – If the certificate chain includes an expired or revoked certificate, verification will fail.
  4. Firewall or Proxy Issues – Some firewalls or proxy servers may interfere with SSL connections, blocking certificate verification.
  5. Incorrect Certificate Paths – If an application does not point to the correct CA certificate file, SSL verification can fail.

How to Fix “Unable to Get Local Issuer Certificate” Error

The solution depends on the application or programming environment where the error occurs. Below are specific fixes for common scenarios.

1. Fixing the Error in cURL

If you encounter this error while using cURL, try the following:

Update the CA Certificates

On Linux/macOS, update the CA certificates by running:

sudo apt update && sudo apt install --reinstall ca-certificates

or

sudo update-ca-certificates

On macOS, update Homebrew and reinstall cURL:

brew update && brew upgrade curl

Specify the CA Bundle Manually

You can manually specify the CA certificate file using:

curl --cacert /etc/ssl/certs/ca-certificates.crt https://example.com

2. Fixing the Error in Python (requests Module)

If you get this error using the requests module in Python, it may be due to an outdated certificate bundle.

Update Python’s SSL Certificates

Run the following command to install the latest certificates:

python -m pip install --upgrade certifi

Then, specify the certificate path in your script:

import requests
import certifi
response = requests.get("https://example.com", verify=certifi.where())
print(response.text)

3. Fixing the Error in Git

If Git fails to verify SSL certificates when cloning or pulling repositories, try these steps:

Manually Set the CA Certificate Path

Find your ca-bundle.crt file, usually located in:

  • Windows: C:Program FilesGitmingw64sslcertsca-bundle.crt
  • macOS/Linux: /etc/ssl/certs/ca-certificates.crt

Then configure Git to use this file:

git config --global http.sslCAInfo "C:Program FilesGitmingw64sslcertsca-bundle.crt"

Disable SSL Verification (Not Recommended)

If you need a temporary workaround, disable SSL verification:

git config --global http.sslVerify false

Warning: Disabling SSL verification can expose your system to security risks.

4. Fixing the Error in Node.js

If you get this error in a Node.js application, update the CA certificates used by the https module.

Set the NODE_EXTRA_CA_CERTS Variable

Download a fresh CA bundle and set the environment variable:

export NODE_EXTRA_CA_CERTS="/etc/ssl/certs/ca-certificates.crt"

On Windows, set it in PowerShell:

$env:NODE_EXTRA_CA_CERTS="C:PathToca-certificates.crt"

Alternatively, install the ssl-root-cas package:

npm install ssl-root-cas

Then update your Node.js code:

const sslRootCAs = require('ssl-root-cas');
require('https').globalAgent.options.ca = sslRootCAs.create();

5. Fixing the Error in OpenSSL

If you’re using OpenSSL and encounter this error, ensure that your system has up-to-date certificates.

Verify the CA Path

Run the following command to check the default CA path:

openssl version -d

Ensure the correct CA file exists at /etc/ssl/certs/ca-certificates.crt (Linux) or C:Program FilesOpenSSL-Win64certsca-bundle.crt (Windows).

Manually Set the CA Path

If needed, manually specify the CA file:

openssl s_client -connect example.com:443 -CAfile /etc/ssl/certs/ca-certificates.crt

Preventing Future SSL Errors

To avoid encountering SSL errors in the future:

  1. Keep Your System Updated – Regularly update your OS and software to ensure you have the latest security patches.
  2. Use a Reliable CA Bundle – Always download CA certificates from trusted sources like Mozilla or your operating system’s package manager.
  3. Avoid Disabling SSL Verification – While it may be a quick fix, disabling SSL verification can expose your system to security threats.

The "Unable to Get Local Issuer Certificate" error can occur in various applications due to missing or outdated certificates. By understanding the cause of the issue and applying the appropriate fix—whether in cURL, Python, Git, Node.js, or OpenSSL—you can ensure secure and error-free connections.

Always keep your certificate store updated and verify that your applications are using the correct CA bundle to prevent future SSL-related errors.