Note that there are some explanatory texts on larger screens.

plurals
  1. POTLS connection with timeouts (and a few other difficulties)
    text
    copied!<p>I have a HTTP client in Python which needs to use TLS. I need not only to make encrypted connections but also to retrieve info from the remote machine, such as the certificate issuer. I need to make connection to many HTTP servers, often badly behaved, so I absolutely need to have a timeout. With non-TLS connections, <code>mysocket.settimeout(5)</code> does what I want.</p> <p>Among the many TLS Python modules:</p> <p><a href="http://pypi.python.org/pypi/python-gnutls" rel="nofollow noreferrer">python-gnutls</a> does not allow to use settimeout() on sockets because it uses non-blocking sockets:</p> <pre><code>gnutls.errors.OperationWouldBlock: Function was interrupted. </code></pre> <p><a href="http://pyopenssl.sourceforge.net/" rel="nofollow noreferrer">python-openssl</a> has a similar issue:</p> <pre><code>OpenSSL.SSL.WantReadError </code></pre> <p>The <a href="http://docs.python.org/library/ssl.html" rel="nofollow noreferrer">SSL module</a> of the standard library does not work with Python 2.5.</p> <p>Other libraries like <a href="http://trevp.net/tlslite/" rel="nofollow noreferrer">TLSlite</a> apparently does not give access to the metadata of the certificate.</p> <p>The program is threaded so I cannot use signals. I need detailed control on the HTTP dialog so I cannot use a standard library like urllib2.</p> <p>Background: this is the survey project <a href="http://www.dnswitness.net/" rel="nofollow noreferrer">DNSwitness</a>. Relevant SO threads: <a href="https://stackoverflow.com/questions/492519/timeout-on-a-python-function-call">Timeout on a Python function call</a> and <a href="https://stackoverflow.com/questions/366682/how-to-limit-execution-time-of-a-function-call-in-python">How to limit execution time of a function call in Python</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload