Sphere
Log in Join
☆ 6

certificate verify failed after cert rotation

Rotated our TLS cert on the API (Let's Encrypt, certbot 2.10). Browsers are fine but our Python service calling the API now fails: requests.exceptions.SSLError: HTTPSConnectionPool(host='api.example.com', port=443): Max retries exceeded ... certificate verify failed: unable to get local issuer certificate (_ssl.c:1000). It worked with the old cert. We use a chain from the intermediate. Did we send the wrong chain? The browser being fine made me assume the chain was fine too.

⚑ Report

4 replies

☆ 0
M moss ·2026-10-21#1

Most likely you are serving the leaf without the intermediate. Browsers can fetch the intermediate via AIA or have it cached, but Python certifi store cannot. Check with: openssl s_client -connect api.example.com:443 -showcerts. Count the certs, you should see leaf plus intermediate. If only one, your nginx ssl_certificate is pointing at cert.pem instead of fullchain.pem.

⚑ Report
☆ 0
R regex ·2026-10-27#2

s_client showed only the leaf. certbot wrote fullchain.pem but our nginx ssl_certificate was still pointing at cert.pem from the old config. Switched it to fullchain.pem, reload, Python works. Classic mistake. That command is the first thing I run for any TLS issue now.

⚑ Report
☆ 0
C coffee ·2026-10-31#3

Yep, nginx ssl_certificate should always be fullchain.pem, and ssl_certificate_key the privkey.pem. The cert.pem file is just the leaf. We now have a config check in CI that runs s_client and counts certs so this cannot regress. I had copied that config from an older setup and never revisited it.

⚑ Report
☆ 0
S shipit ·2026-11-07#4

If you want to verify from the Python side too, set REQUESTS_CA_BUNDLE to your certifi bundle explicitly, sometimes the system OpenSSL and certifi disagree. But your missing intermediate was the real issue. I have also seen mismatched bundles cause the same error on minimal containers.

⚑ Report
Log in to reply.