Zum Inhalt springen
ecdsa.com
Python ssl module (OpenSSL)Python cryptography

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

So behebst du den Fehler

  1. 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. 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. 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

Gesamte Signaturfehler-Datenbank durchsuchen