Fehlermeldung
[SSL: WRONG_VERSION_NUMBER] wrong version number
Auch ausgegeben als
- ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number
Danach folgt eine Quellcode-Position wie „(_ssl.c:1082)“. urllib zeigt die Meldung innerhalb von „<urlopen error …>“, requests und urllib3 innerhalb von „Max retries exceeded … (Caused by SSLError(…))“.
Python ssl module (OpenSSL) — ssl.SSLError, SSL_R_WRONG_VERSION_NUMBER
Was der Fehler bedeutet
Python hat einen TLS-Handshake begonnen, und die zurückgekommenen Bytes sind kein TLS-Record: OpenSSL liest sie als Record-Header mit einer unmöglichen Protokollversion. In der Praxis spricht die Gegenstelle auf diesem Port Klartext – ein HTTP-Server, ein Proxy, der reines HTTP erwartet, oder ein SMTP-Server, der vor STARTTLS erst den Austausch der Begrüßung erwartet.
Warum der Fehler auftritt
https:// auf einen Port mit reinem HTTP
häufigEntwicklungsserver, interne Dienste hinter einem TLS-terminierenden Load Balancer und Metrics-Endpunkte lauschen oft auf reinem HTTP. Verwendest du https:// mit ihrem Port, erscheint sofort dieser Fehler.
Der Proxy ist als https:// konfiguriert, spricht aber HTTP
häufigHTTPS_PROXY=https://proxy:3128 oder proxies={"https": "https://…"} lässt urllib3 TLS mit dem Proxy starten. Seit urllib3 1.26 wird das wörtlich umgesetzt, und die meisten Firmen-Proxys akzeptieren von Clients nur reines HTTP.
smtplib.SMTP_SSL auf einem STARTTLS-Port
häufigPort 587 (und 25) beginnt im Klartext und wechselt per STARTTLS zu TLS; implizites TLS liegt auf 465. SMTP_SSL gegen 587 scheitert auf diese Weise, ebenso IMAP4_SSL gegen 143.
Ein Captive Portal oder Filter antwortet mit reinem HTTP
gelegentlichHotel- oder Gast-WLANs und manche Sicherheits-Appliances fangen die Verbindung ab und antworten mit einer HTTP-Seite.
So behebst du den Fehler
- 1.
Herausfinden, was der Port spricht
Rufe den Port mit http:// auf und versuche einen TLS-Handshake mit openssl s_client; verwende dann das passende Schema oder den richtigen Port.
bash curl -si http://127.0.0.1:8080/ | head -1 # an HTTP status line: the port is plain HTTP openssl s_client -connect 127.0.0.1:8443 -brief </dev/null # a TLS summary: the port speaks TLS - 2.
Proxy-URLs mit http:// angeben
Der Eintrag https im Dictionary proxies nennt den Proxy für HTTPS-Ziele; das Schema seiner URL beschreibt, wie mit dem Proxy selbst kommuniziert wird. Der Verkehr zum Ziel bleibt trotzdem Ende-zu-Ende-TLS.
python import requests # Most forward proxies take plain HTTP from the client and tunnel TLS with CONNECT proxies = {"https": "http://proxy.example.net:3128"} # http:// here, not https:// requests.get("https://api.example.com/", proxies=proxies) - 3.
E-Mail: Klasse passend zum Port wählen
Verwende SMTP + starttls() auf 587 und SMTP_SSL auf 465; dieselbe Regel gilt für imaplib und poplib.
python import smtplib, ssl ctx = ssl.create_default_context() # Port 587: plain connection first, then STARTTLS with smtplib.SMTP("mail.example.com", 587) as s: s.starttls(context=ctx) # Port 465: implicit TLS from the first byte with smtplib.SMTP_SSL("mail.example.com", 465, context=ctx) as s: s.noop()
Verwandte Fehler
curl: (35) TLS connect error: error:0A00010B:SSL routines::wrong version numbercurl (OpenSSL backend)SSL routines:tls_validate_record_header:wrong version numberOpenSSL 3 (openssl s_client and any OpenSSL-based client)code: 'ERR_SSL_WRONG_VERSION_NUMBER'Node.js tls.connect / fetch (undici)[SSL: UNEXPECTED_EOF_WHILE_READING] EOF occurred in violation of protocolPython ssl module (OpenSSL)