Is HTTPSConnection thread-safe?

Jeremy Jones zanesdad at
Fri Aug 20 13:34:00 CEST 2004

Joe Wong wrote:

> Hi,
> I have a small program using HTTPSConnection to issue a POST on the
> server. When multiple threads of the same program is running, I got
> the error:
> Exception in thread Thread-3:
> Traceback (most recent call last):
> File "C:\PYTHON23\lib\", line 436, in __bootstrap
> File "C:\PYTHON23\lib\", line 416, in run
> self.__target(*self.__args, **self.__kwargs)
> File "", line 27, in thread_func
> conn.request("POST", CGI_PATH, params, headers)
> File "c:\python23\lib\", line 718, in request
> self._send_request(method, url, body, headers)
> File "c:\python23\lib\", line 739, in _send_request
> self.endheaders()
> File "c:\python23\lib\", line 712, in endheaders
> self._send_output()
> File "c:\python23\lib\", line 597, in _send_output
> self.send(msg)
> File "c:\python23\lib\", line 564, in send
> self.connect()
> File "c:\python23\lib\", line 985, in connect
> ssl = socket.ssl(sock, self.key_file, self.cert_file)
> File "C:\Python23\lib\", line 73, in ssl
> return _realssl(sock, keyfile, certfile)
> sslerror: SSL_CTX_new error
> in random order. Is there any fix / patches for this?
> Regards,
> - Joe

Are you passing the same HTTPSConnection object to a bunch of threads?
With just a cursory glance at the httplib module, it doesn't look like
it is thread safe (meaning I saw no thread imports, no references to
locks, etc.). If, for some reason, you feel it necessary to pass the
same HTTPSConnection object to multiple threads, you will probably want
to write a thread-safe wrapper for HTTPSConnection. I can't think why
you would want to pass the same conn object to multiple threads rather
than creating a new one per thread - unless you want to have one and
only one persistent connection among all threads (using keepalives, I

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list