title: SSL illegal state exception in jython
body: <p>I am getting the following error frequently but not always,</p>
  
  <pre><code>in __call__ return self.__sendself.__name args File "/Lib/cvplibrary/SSLCertificateWrapper.py" line 51 in wrapped res = f*args **kwargs File "/Lib/jsonrpclib/jsonrpc.py" line 240 in _request response = self._run_requestrequest File "/Lib/jsonrpclib/jsonrpc.py" line 254 in _run_request response = self.__transport.request File "/Lib/xmlrpclib.py" line 1264 in request return self.single_requesthost handler request_body verbose File "/Lib/xmlrpclib.py" line 1292 in single_request self.send_contenth request_body File "/Lib/jsonrpclib/jsonrpc.py" line 129 in send_content connection.endheaders File "/Lib/httplib.py" line 997 in endheaders self._send_outputmessage_body File "/Lib/httplib.py" line 850 in _send_output self.sendmsg File "/Lib/httplib.py" line 812 in send self.connect File "/Lib/httplib.py" line 1204 in connect self.sock = ssl.wrap_socketsock self.key_file self.cert_file File "/Lib/_socket.py" line 357 in handle_exception return method_or_function*args **kwargs File "/Lib/_socket.py" line 357 in handle_exception return method_or_function*args **kwargs File "/Lib/ssl.py" line 287 in wrap_socket return SSLSocket File "/Lib/ssl.py" line 116 in __init__ self.do_handshake File "/Lib/ssl.py" line 165 in do_handshake raise SSLErrorSSL_ERROR_SSL e.strerror _socket.SSLError: [Errno 1] Illegal state exception
  </code></pre>
  
  <p>Following is the code I am trying to execute by using <strong>jython</strong>,</p>
  
  <pre><code>import jsonrpclib
  url = 'https://user:password@localhost/'
  ss = jsonrpclib.Server( url )
  version = ss.runCmds("ifconfig" )
  print version
  </code></pre>
  
  <p>I am using jsonrpc lib with an added wrapper to the method " _request" as follows</p>
  
  <pre><code>@trust_all_certificates
  def _request(self, methodname, params, rpcid=None):
      request = dumps(params, methodname, encoding=self.__encoding,
                      rpcid=rpcid, version=self.__version)
      response = self._run_request(request)
      check_for_errors(response)
      return response['result']
  </code></pre>
  
  <p>and the wrapper is taken from : <a href="http://tech.pedersen-live.com/2010/10/trusting-all-certificates-in-jython/" rel="nofollow">http://tech.pedersen-live.com/2010/10/trusting-all-certificates-in-jython/</a> as follows,</p>
  
  <pre><code>def trust_all_certificates(f):
  '''Decorator function that will make it so the context of the    decorated method
  will run with our TrustManager that accepts all certificates'''
  def wrapped(*args, **kwargs):
      # Only do this if running under Jython
      if 'java' in sys.platform:
          from javax.net.ssl import SSLContext
          SSLContext.setDefault(TRUST_ALL_CONTEXT)
          try:
              res = f(*args, **kwargs)
              return res
          finally:
              SSLContext.setDefault(DEFAULT_CONTEXT)
      else:
          return f(*args, **kwargs)
  return wrapped
  </code></pre>
  
  <p>how can this problem be solved?</p>