title: Httplib - Check if connection is open
body: <p>I'm opening connections to a server and sending chunk-encoded HTTP posts. The server that I connect to closes connections if no data has been sent in a minute, so I would like to check if the connection is still open as I write data.</p>
  
  <p>The connections are initialized with something like:</p>
  
  <pre><code>conn = httplib.HTTPConnection(url, 80)
  conn.putrequest('POST', '/')
  conn.putheader('Host', hosturl)
  conn.putheader('Transfer-Encoding', 'chunked')
  conn.putheader('Connection', 'close')
  conn.endheaders()
  </code></pre>
  
  <p>And data gets written with:</p>
  
  <pre><code>conn.send('{msglen}\r\n{msg}\r\n'.format(msglen=msglen, msg=msg))
  </code></pre>
  
  <p>Is there a way to tell if this connection is open? I noticed the exception <code>httplib.NotConnected</code>, but if I run:</p>
  
  <pre><code>conn.close()
  conn.send(data)
  </code></pre>
  
  <p>The exception does not get thrown.</p>
  
  <p>Thanks for the help!</p>