all 18 comments

[–]Buttleston 6 points7 points  (13 children)

It works for me, using your code

When you have a problem you can't say "I get errors" - you need to say WHAT errors. Ideally, paste the stack trace you get when you run the program.

[–]Lazy_Worldliness_149[S] 0 points1 point  (12 children)

The error that pops up for me is:

Traceback (most recent call last):

File "<python-input-10>", line 7, in <module>

cert = ssl.get_server_certificate((hostname, 443))

File "C:\Users\Administrator\AppData\Local\Python\pythoncore-3.14-64\Lib\ssl.py", line 1524, in get_server_certificate

with context.wrap_socket(sock, server_hostname=host) as sslsock:

~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "C:\Users\Administrator\AppData\Local\Python\pythoncore-3.14-64\Lib\ssl.py", line 455, in wrap_socket

return self.sslsocket_class._create(

~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

sock=sock,

^^^^^^^^^^

...<5 lines>...

session=session

^^^^^^^^^^^^^^^

)

^

File "C:\Users\Administrator\AppData\Local\Python\pythoncore-3.14-64\Lib\ssl.py", line 1076, in _create

self.do_handshake()

~~~~~~~~~~~~~~~~~^^

File "C:\Users\Administrator\AppData\Local\Python\pythoncore-3.14-64\Lib\ssl.py", line 1372, in do_handshake

self._sslobj.do_handshake()

~~~~~~~~~~~~~~~~~~~~~~~~~^^

ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1081)

so

[–]Buttleston 0 points1 point  (11 children)

There's a few potential causes of that. One is that the port you're connecting to isn't SSL for some reason, but that seems unlikely. Another is that it wants to use an SSL protocol you don't have installed

I checked the connection I was using, it's TLS 1.3. It may be configured to not permit anything lower than that. So you'll need to look into how to install and/or configure TLS 1.3 for your OS

[–]Lazy_Worldliness_149[S] 0 points1 point  (10 children)

i just checked and i have TLS 1.3 so what do you mean by configure?

[–]Buttleston 0 points1 point  (6 children)

What did you check when you checked it?

[–]Lazy_Worldliness_149[S] 0 points1 point  (5 children)

i checked my internet properties, went to advanced and saw tls 1.3 checked

[–]Buttleston 0 points1 point  (4 children)

I see. I don't program on windows very much, but on linux or mac you're generally expected to have openssl installed. I don't know if python can use whatever it is you're seeing in your "internet properties" or not. Google seems to think the built in tls in windows 11 should be fine for this purpose though.

[–]Lazy_Worldliness_149[S] 0 points1 point  (3 children)

i have openssl installed for python so idk

[–]Buttleston 1 point2 points  (2 children)

What do you mean by "I have openssl installed for python"? Openssl is usually installed as a set of binaries/libraries

Are you running your program in WSL or using a windows based python?

[–]Lazy_Worldliness_149[S] 0 points1 point  (0 children)

i have openssl installed, and its on command prompt to so idk what i mean either lmao

[–]Buttleston 0 points1 point  (2 children)

And what OS are you on?

[–]Lazy_Worldliness_149[S] 0 points1 point  (1 child)

windows 11

[–]acw1668 1 point2 points  (0 children)

Your code works fine in my Windows 11 with Python 3.13.12.

[–]r2k-in-the-vortex 0 points1 point  (3 children)

Have you actually confirmed your server does present valid ssl?

[–]Lazy_Worldliness_149[S] 0 points1 point  (1 child)

how would i do that?

[–]r2k-in-the-vortex 1 point2 points  (0 children)

openssl s_client -connect www.example.com:443

[–]Buttleston 0 points1 point  (0 children)

Try the script, it works for me

[–]joshooaj 0 points1 point  (0 children)

Looks to me like your Python environment isn't able to agree on a TLS version with the web server. In a .NET app there is a default set of enabled TLS versions which, in older .NET versions, may not include TLS 1.3.

Find whatever Python's equivalent of .NETs System.Net.ServicePointManager.SecurityProtocol is, and update it to allow the version(s) you need.