Python/OpenSSL: SSLV3_ALERT_HANDSHAKE_FAILURE or CA_MD_TOO_WEAK — OpenSSL security level 2 rejects legacy servers
A modern Python/OpenSSL (Debian/Ubuntu security level 2) refuses weak keys, SHA-1 or small DH from an older server.
[SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure[SSL: DH_KEY_TOO_SMALL] dh key too small[SSL: CA_MD_TOO_WEAK] ca md too weakssl.SSLError: [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] Meaning
Best fix is on the server (2048-bit keys, SHA-256, modern ciphers). For a trusted legacy endpoint only, lower the level in the context: ctx.set_ciphers("DEFAULT:@SECLEVEL=1"), or CipherString = DEFAULT@SECLEVEL=1 in openssl.cnf.
Common causes
- Server with DH/RSA key under 2048 bits
- SHA-1 signed certificate
- RC4/3DES-only server
- Distribution tightened defaults
- OpenSSL 3 security level
⚡ Quick fix
- Upgrade the server's TLS parameters
- Scope
@SECLEVEL=1to that one connection - Avoid lowering the system-wide level
Detailed fix by platform
Python
- python
import ssl ctx = ssl.create_default_context() ctx.set_ciphers("DEFAULT:@SECLEVEL=1") # trusted legacy server only
How to diagnose
- Server — Weak params?
- Level — Lowered scoped?
- Upgrade — Possible?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- ca md too weak / ee key too small OpenSSL: error:0A00018E:SSL routines::ca md too weak / error:140AB18F:SSL routines:SSL_CTX_use_certificate:ee key too small
- certifi requests SSLError: CERTIFICATE_VERIFY_FAILED because certifi is outdated (missing a new root CA)
- ConnectionRefusedError [Errno 111] (SMTP) Python: ConnectionRefusedError: [Errno 111] Connection refused — smtplib connect to localhost:25
Most viewed in SSL / TLS
- DST Root CA X3 expired (old clients fail) Old clients: certificate has expired — Let's Encrypt chain uses expired DST Root CA X3 (OpenSSL 1.0.x, Android < 7.1.1)
- Keystore was tampered with, or password was incorrect Java keytool: java.io.IOException: Keystore was tampered with, or password was incorrect
- Challenge failed for domain Let’s Encrypt / Certbot: Challenge failed for domain example.com — Invalid response from http://example.com/.well-known/acme-challenge/x: 404
Other ways to find it
Where this error sits
Origin: Network. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 18 Nov 2026