Python code troubleshooting

I am on the first steps in learning python, so please excuse my questions. I want to run the code below (taken from: http://docs.python.org/library/ssl.html ):

import socket, ssl, pprint s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # require a certificate from the server ssl_sock = ssl.wrap_socket(s, ca_certs="F:/cert", cert_reqs=ssl.CERT_REQUIRED) ssl_sock.connect(('www.versign.com', 443)) print repr(ssl_sock.getpeername()) print ssl_sock.cipher() print pprint.pformat(ssl_sock.getpeercert()) # Set a simple HTTP request -- use httplib in actual code. ssl_sock.write("""GET / HTTP/1.0\r Host: www.verisign.com\r\n\r\n""") # Read a chunk of data. Will not necessarily # read all the data returned by the server. data = ssl_sock.read() # note that closing the SSLSocket will also close the underlying socket ssl_sock.close() 

I got the following errors:

Traceback (last last call): File "C: \ Users \ e \ workspace \ PythonTesting \ source \ HelloWorld.py", line 38, at ssl_sock.connect (('www.versign.com', 443))

File "C: \ Python27 \ lib \ ssl.py", line 331, in connect

 self._real_connect(addr, False) 

File "C: \ Python27 \ lib \ ssl.py", line 314, in _real_connect

self.ca_certs, self.ciphers)

ssl.SSLError: [Errno 185090050] _ssl.c: 340: error: 0B084002: x509 verification procedures: X509_load_cert_crl_file: system lib

The error report in python does not look like a guideline to find the source of the problem. I could be wrong. Can someone help me tell me what the problem is in the code?

+4
source share
3 answers

This is one area where, as you know, it is difficult to use the standard Python library. Instead, you can use the query library. Documentation for sending certificates can be obtained at: http://docs.python-requests.org/en/latest/user/advanced/#ssl-cert-verification

+3
source

Your code refers to a certificate file on disk "F:" (using the ca_certs parameter) that was not found at run time - is there one?

See related documentation :

The ca_certs file contains a set of concatenated "authority certificates" that are used to verify the certificates transferred from the other end of the connection.

+2
source

Is there a link to a certificate in your file system? I think the error is due to an invalid certificate from this code:

ssl_sock = ssl.wrap_socket (s, ca_certs = "F: / cert", cert_reqs = ssl.CERT_REQUIRED)

0
source

Source: https://habr.com/ru/post/1439660/


All Articles