alekstorm / backports.ssl

UNMAINTAINED - The Python 3.4 standard `ssl` module API implemented on top of pyOpenSSL

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Python 2.6.6 (Windows) - backports.ssl example code does not run

ph-hs opened this issue · comments

commented

This:

import backports.ssl as ssl
import socket

context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
context.verify_mode = ssl.CERT_REQUIRED

conn = context.wrap_socket(socket.socket(socket.AF_INET))
conn.connect(('google.com', 443))
print conn.getpeercert()
conn.close()

Results in:

Traceback (most recent call last):
  File "test.py", line 8, in <module>
    conn.connect(('google.com', 443))
  File "C:\Python26\lib\site-packages\backports\ssl\core.py", line 258, in connect
    self.do_handshake()
  File "C:\Python26\lib\site-packages\backports\ssl\core.py", line 261, in do_handshake
    _safe_ssl_call(False, self._conn, 'do_handshake')
  File "C:\Python26\lib\site-packages\backports\ssl\core.py", line 222, in _safe_ssl_call
raise SSLError(*e.args)
backports.ssl.core.SSLError: [('SSL routines', 'ssl3_get_server_certificate', 'certificate verify failed')]

This and #16 look like the root certificates are not available on your Windows installation. I've run into this several times on Windows. The example code should definitely detect this scenario and fail early with a useful error, and the documentation should offer basic guidance on how the user may resolve that problem.

If it helps anyone I was on Windows10 that was upgraded automatically last summer from Windows8.1