开发者

socket.setdefaulttimeout interacting with M2Crypto connection

I'm making a secure SSL connection to a se开发者_开发知识库rver using python and M2Crypto. See code below.

from M2Crypto import SSL, m2,x509
from M2Crypto.m2xmlrpclib import Server, SSL_Tranport
ctx = SSL.Context()
m2.ssl_ctx_use_pkey_privkey(ctx.ctx,myKey.pkey)
m2.ssl_ctx_use_x509(ctx.ctx,myCert.x509)
server = Server(serverUrl, SSL_Transport(ctx))
server.ping()

The above works fine. If I try to change the default socket timeout by adding the following two lines at the beginning of the code, I get a protocol error.

import socket
socket.setdefaulttimeout(40)

This is the error I receive:

File "/usr/local/lib/python2.4/xmlrpclib.py", line 1096, in call return self.__send(self.__name, args) File "/usr/local/lib/python2.4/xmlrpclib.py", line 1383, in __request verbose=self.__verbose File "/usr/local/lib/python2.4/site-packages/M2Crypto/m2xmlrpclib.py", line 68, in request headers xmlrpclib.ProtocolError:

Why is the default socket timeout causing problems?


There is a patch that can fix this. It is for Linux only. See Bug 2341 --> https://bugzilla.osafoundation.org/show_bug.cgi?id=2341

I have not tried the patch. I will use a different work around. I set the socket timeout to None then run my M2Crypto code then set the socket timeout back to the value I need for the rest of my code.

origTimeout = socket.getdefaulttimeout()
socket.setdefaulttimeout(None)
# run M2Crypto code
socket.setdefaulttimeout(origTimeout)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜