我经常收到以下错误,但并非总是如此,
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
以下是我尝试使用 jython ,
执行的代码import jsonrpclib
url = 'https://user:password@localhost/'
ss = jsonrpclib.Server( url )
version = ss.runCmds("ifconfig" )
print version
我正在使用jsonrpc lib和方法的附加包装" _request"如下
@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']
,包装器取自:http://tech.pedersen-live.com/2010/10/trusting-all-certificates-in-jython/,如下所示,
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
如何解决这个问题?
答案 0 :(得分:3)
我通过增加ssl.py第165行(Jython 3.7库)中的等待时间来修复此问题
time.sleep(0.005) # Necessary apparently for the handler to get into a good state
try:
self._sock._handle_channel_future(handshake, "SSL handshake")
except socket_error, e:
raise SSLError(SSL_ERROR_SSL, e.strerror)