title: Python SSL wrap_socket failed with SSLError, Errno 336265218
body: <p>I have simple client/server SSL code which worked fine on Python 3.2. However, I decided to switch over to 2.7 (due to abundance of third party modules), and now the code is failing. The code is as follows:</p>
  
  <p>Client:</p>
  
  <pre><code>def connect(self):
      self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
      self.sock.connect(('localhost', 4430))
      self.ssl_sock = ssl.wrap_socket(self.sock, cert_reqs = ssl.CERT_NONE, ssl_version = ssl.PROTOCOL_TLSv1)
  </code></pre>
  
  <p>Server:</p>
  
  <pre><code>self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
      self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
      self.sock.bind((self.hostname, 4430))
      self.sock.listen(5)
      while True:
          self.newsocket, self.fromaddr = self.sock.accept()
          self.ssl_sock = ssl.wrap_socket(
                              self.newsocket, 
                              server_side = True,
                              certfile = "cert.pem",
                              ssl_version=ssl.PROTOCOL_TLSv1
          ) 
  
          self._handle_client(self.ssl_sock)
  </code></pre>
  
  <p>The cert.pem (located in same directory as server .py file):</p>
  
  <pre><code>-----BEGIN RSA PRIVATE KEY-----
  (812 "random" characters here)
  -----END RSA PRIVATE KEY-----
  -----BEGIN CERTIFICATE-----
  (1260 "random" characters here)
  -----END CERTIFICATE-----
  </code></pre>
  
  <p>The failure is as follows:<br>
  1. server waits on self.sock.accept()<br>
  2. client connects with self.sock.connect()<br>
  3. server proceeds to wrap_socket, which fails with the following error:<br></p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\Program Files\Python27\lib\multiprocessing\process.py", line 258, in _bootstrap
      self.run()
    File "C:\workspace\projectc\server\server\clientlistener.py", line 49, in run
      ssl_version=ssl.PROTOCOL_TLSv1
    File "C:\Program Files\Python27\lib\ssl.py", line 381, in wrap_socket
      ciphers=ciphers)
    File "C:\Program Files\Python27\lib\ssl.py", line 141, in __init__
      ciphers)
  SSLError: [Errno 336265218] _ssl.c:351: error:140B0002:SSL routines:SSL_CTX_use_PrivateKey_file:system lib
  </code></pre>
  
  <p>P.S.<br>
  1) I have suspicions about the wrap_socket call because even when I use a non-existent file for certfile, the same error results.<br>
  2) I tried the alternative wrapping on the python documentation on ssl (i.e. with ssl.SSLContext) and it's odd that 'module' object has no attribute 'SSLContext', when it is part of the ssl module. This wasn't an issue when I tried it with Python 3.2.</p>
  
  <p><strong>Update:<br></strong>
  I have found that the problem only occurs when I'm doing "run" from within Eclipse, not so when I run both files from separate command prompts. Still investigating the issue...</p>
  
  <p><strong>Update 2:</strong>
  I tried a very simple client/server script with the SAME code and it works. Now, with the server code sitting inside a multiprocessing subprocess (launched by the main server process), it seems not to work. Related?</p>