I am trying to create TLS connection with a server. My simple script is below. However, when I run it, I get this error:
Traceback (most recent call last):
File "tls_client.py", line 28, in <module>
sslSocket.connect((domain, 443))
File "C:\Python36\lib\ssl.py", line 1100, in connect
self._real_connect(addr, False)
File "C:\Python36\lib\ssl.py", line 1091, in _real_connect
self.do_handshake()
File "C:\Python36\lib\ssl.py", line 1068, in do_handshake
self._sslobj.do_handshake()
File "C:\Python36\lib\ssl.py", line 689, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833)
The script:
import socket, ssl
context = ssl.SSLContext(protocol = ssl.PROTOCOL_TLS_CLIENT)
context.set_ciphers('ECDHE-RSA-AES128-GCM-SHA256')
context.verify_mode = ssl.CERT_OPTIONAL
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sslSocket = context.wrap_socket(s, server_hostname = 'www.google.com')
sslSocket.connect((domain, 443))
What is the cause of the problem? I tried couple of websites like www.verisign.com
but I also get the same error.
EDIT:
I do not want to turn verify_mode off. I need it on. I think google.com
and verisign.com
have verifiable certificates.
EDIT 2: Based on a solution in the link provided: I run pip install certifi Then tried to run this command in Windows command but get an error:
>/Applications/Python\ 3.6/Install\ Certificates.comman
'/Applications/Python\' is not recognized as an internal or external command,
operable program or batch file.