SSLZeroReturnError error only in python 3.10

Viewed 207

I use that code to connect for ssl server

import socket
import ssl
import sys
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
ssl_socket = ssl.wrap_socket(sock)
ssl_socket.connect((sys.argv[1], int(sys.argv[2])))

When I run this code with pyhton3.7 everything if fine

But when I run this code with Python 3.10.4 I got that error:

Traceback (most recent call last):
  File "test_ssl.py", line 6, in <module>
    ssl_socket.connect((sys.argv[1], int(sys.argv[2])))
  File "/usr/lib/python3.10/ssl.py", line 1374, in connect
    self._real_connect(addr, False)
  File "/usr/lib/python3.10/ssl.py", line 1365, in _real_connect
    self.do_handshake()
  File "/usr/lib/python3.10/ssl.py", line 1341, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLZeroReturnError: TLS/SSL connection has been closed (EOF) (_ssl.c:997)

How can I fix that that this code will work with Python 3.10.4?

In python 3.10.4 I have OpenSSL 3.0.2 15 Mar 2022

In python 3.7 I have OpenSSL 3.0.2 15 Mar 2022

0 Answers
Related