Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > de.comp.lang.python > #6271
| From | "Peter J. Holzer" <hjp-usenet4@hjp.at> |
|---|---|
| Newsgroups | de.comp.lang.python |
| Subject | Re: [Python-de] Re: ssl.wrap_socket? |
| Date | 2025-03-23 10:38 +0100 |
| Organization | LUGA |
| Message-ID | <slrnvtvll1.3l8sk.hjp-usenet4@trintignant.hjp.at> (permalink) |
| References | <vrno65$k58$1@rusnews.informatik.uni-stuttgart.de> <7d259392-b0cd-4ed8-81df-b2194f467db8@chrisarndt.de> <vroj87$rg9$1@rusnews.informatik.uni-stuttgart.de> |
On 2025-03-23 09:11, Ulli Horlacher <framstag@rus.uni-stuttgart.de> wrote:
> Ich hab das nun so probiert:
>
> sock = socket.create_connection((server,port))
> (...)
> SSLContext = ssl.create_default_context()
Du willst es den Lesern Deines Codes auch künstlich schwer machen, oder?
Eine Variable so zu nennen wie eine Klasse der Library, die man gerade
verwendet, ist ziemlich verwirrend.
> 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
Dann gib den Namen halt an. wrap_socket hat einen Parameter dafür:
https://docs.python.org/3/library/ssl.html#ssl.SSLContext.wrap_socket
> Dabei hattte ich doch den Server hostname angegeben bei Erzeugung von sock.
Ich glaube nicht, dass sich ein Socket merkt, welchen Hostnamen Du beim
connect angegeben hast. Nach dem DNS-Lookup braucht er den schließlich
nicht mehr.
#v+
>>> import socket
>>> s = socket.create_connection(("mail.hjp.at", 25))
>>> s
<socket.socket fd=3, family=2, type=1, proto=6, laddr=('212.17.106.130', 54278), raddr=('212.17.106.138', 25)>
#v-
hjp
Back to de.comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar
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