Fixing Redis ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] unable to get local issuer certificate

intermediate๐Ÿ”ด Redis2026-07-26| Python 3.8+, redis-py 4.0+, Redis 6.0+ with TLS, AWS ElastiCache, Azure Cache for Redis, or self-hosted Redis.

Error Message

ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123)
#redis#python#ssl#tls#devops#aws

The Problem

Trying to connect to a Redis instance over TLS? You might run into a frustrating traceback that looks like this:

ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123)

This error happens when your Python application tries to verify the Redis server's identity but fails. Essentially, your client sees the SSL certificate but doesn't recognize the authority that signed it. Without a trusted link back to a root certificate in your local store, the connection drops for security reasons.

Why Verification Fails

SSL handshakes fail for a few specific reasons. One common culprit is a Missing CA Bundle. Your client might not know where the root Certificate Authority (CA) files live on your disk.

If you use Self-Signed Certificates for internal testing, your client will reject them by default. Managed services like AWS ElastiCache or Azure Cache for Redis also use specific CAs. These might not exist in your environment's default trust store. Finally, Python on macOS is notorious for this. It often uses its own internal certificate bundle rather than the system's keychain.

Step-by-Step Fixes

1. Point to the CA Certificate Manually

Explicitly pointing your client to a trusted CA file is the most reliable fix for production environments. This is common when using AWS ElastiCache, which often requires the amazon-trust-services.pem file.

import redis

# Example: Path to your downloaded CA certificate
ca_cert_path = "/etc/ssl/certs/redis-ca.pem"

r = redis.Redis(
    host='your-redis-cluster.cache.amazonaws.com',
    port=6379,
    ssl=True,
    ssl_ca_certs=ca_cert_path,
    password='your-secure-password'
)

# If successful, this returns True
print(r.ping())

2. Leverage the Certifi Package

Most public CAs are already tracked by the certifi library. This is the gold standard for fixing SSL issues on macOS or inside Docker containers. First, install the package:

pip install certifi

Then, tell redis-py to use certifi's certificate store:

import redis
import certifi

r = redis.Redis(
    host='your-redis-host',
    port=6379,
    ssl=True,
    ssl_ca_certs=certifi.where()
)

print(r.ping())

3. Update OS-Level Certificates

Sometimes the root cause is an outdated operating system. If your local store is old, it won't recognize newer certificates from providers like Let's Encrypt.

On Ubuntu/Debian:

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

On macOS: If you installed Python 3.11 or 3.12 via the official installer, you must run the included command script to install certificates. Replace 3.x with your actual version:

/Applications/Python\ 3.x/Install\ Certificates.command

4. Disable Verification (Development Only)

Working on a local dev machine? You can bypass the check entirely. Never do this in production as it leaves your connection vulnerable to man-in-the-middle attacks.

import redis
import ssl

r = redis.Redis(
    host='localhost',
    port=6379,
    ssl=True,
    ssl_cert_reqs=None # Skips validation
)

print(r.ping())

Testing the Connection

Run a simple PING. If the client returns PONG, your TLS handshake is working perfectly. If you still have trouble, try testing with redis-cli to see if the issue is Python-specific:

# Test with redis-cli
redis-cli -h your-host -p 6379 --tls --cacert /path/to/ca.pem ping

How to Prevent Future Failures

  • Automate Updates: Run pip install --upgrade certifi monthly to keep your root hints fresh.
  • Monitor Expiry: Certificates often expire every 90 days. Set up alerts to renew them before they break your app.
  • Centralize Config: Use environment variables like REDIS_CA_PATH instead of hardcoding strings in your scripts.

Related Error Notes