Groups | Search | Server Info | Keyboard shortcuts | Login | Register


Groups > de.comp.lang.python > #6270

Re: [Python-de] Re: ssl.wrap_socket?

From Ulli Horlacher <framstag@rus.uni-stuttgart.de>
Newsgroups de.comp.lang.python
Subject Re: [Python-de] Re: ssl.wrap_socket?
Date 2025-03-23 09:11 +0000
Organization University of Stuttgart, FRG
Message-ID <vroj87$rg9$1@rusnews.informatik.uni-stuttgart.de> (permalink)
References <vrno65$k58$1@rusnews.informatik.uni-stuttgart.de> <7d259392-b0cd-4ed8-81df-b2194f467db8@chrisarndt.de>

Show all headers | View raw


Christopher Arndt <chris@chrisarndt.de> wrote:
> Am 23.03.25 um 02:29 schrieb Ulli Horlacher:
>>
>>      sock = ssl.SSLContext.wrap_socket(sock)
>> 
>> Ich hab da wohl was nicht verstanden. Wie gehts richtig?
> 
> Du musst die wrap_socket Methode auf einer *Instanz* der Klasse 
> SSLContext aufrufen.

Mit Klassen hab ich bisher noch nicht gearbeitet, jedenfalls nicht
explizit.


> Diese Instanz erzeugst du am besten mit:
> 
> context = ssl.create_default_context()

Ich hab das nun so probiert:

    sock = socket.create_connection((server,port))
    (...)
    SSLContext = ssl.create_default_context()
    sock = SSLContext.wrap_socket(sock)

Das ergibt leider die Fehlermeldung:

  File "/local/home/framstag/python/./fexit.py", line 906, in http_connect
    sock = SSLContext.wrap_socket(sock)
  File "/usr/lib/python3.10/ssl.py", line 513, in wrap_socket
    return self.sslsocket_class._create(
  File "/usr/lib/python3.10/ssl.py", line 1028, in _create
    raise ValueError("check_hostname requires server_hostname")
ValueError: check_hostname requires server_hostname


Dabei hattte ich doch den Server hostname angegeben bei Erzeugung von sock.



> Hier gibt es Beispielcode:
> 
> https://docs.python.org/3/library/ssl.html#socket-creation

Da ist leider kein Beispiel dabei, wie man einen vorhandenen socket in
einen TLS socket wandelt, wie es zuvor bei Python2 ging mit:

sock = ssl.wrap_socket(sock)

Bzw es geht so ja noch immer, nur kommt da die Warnung.
Die will ich wegkriegen.

-- 
Ullrich Horlacher              Server und Virtualisierung
Rechenzentrum TIK
Universitaet Stuttgart         E-Mail: horlacher@tik.uni-stuttgart.de
Allmandring 30a                Tel:    ++49-711-68565868
70569 Stuttgart (Germany)      WWW:    https://www.tik.uni-stuttgart.de/

Back to de.comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

ssl.wrap_socket? Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2025-03-23 01:29 +0000
  [Python-de] Re: ssl.wrap_socket? Christopher Arndt <chris@chrisarndt.de> - 2025-03-23 03:42 +0100
    Re: [Python-de] Re: ssl.wrap_socket? Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2025-03-23 09:11 +0000
      Re: [Python-de] Re: ssl.wrap_socket? "Peter J. Holzer" <hjp-usenet4@hjp.at> - 2025-03-23 10:38 +0100
        Re: [Python-de] Re: ssl.wrap_socket? Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2025-03-23 10:08 +0000
          Re: [Python-de] Re: ssl.wrap_socket? Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2025-03-23 10:29 +0000
          [Python-de] Re: ssl.wrap_socket? Hartmut Goebel <h.goebel@goebel-consult.de> - 2025-03-23 16:25 +0100

csiph-web