title: HTTPS connection Python
body: <p>I am trying to verify the that target exposes a https web service. I have code to connect via HTTP but I am not sure how to connect via HTTPS. I have read you use SSL but I have also read that it did not support certificate errors. The code I have got is from the python docs:</p>
  
  <pre><code>import httplib
  conn = httplib.HTTPConnection("www.python.org")
  conn.request("GET", "/index.html")
  r1 = conn.getresponse()
  print r1.status, r1.reason
  </code></pre>
  
  <p>Does anyone know how to connect to HTTPS?</p>
  
  <p>I already tried the HTTPSConenction but it responds with an error code claiming httplib does not have attribute HTTPSConnection. I also don't have socket.ssl available.</p>
  
  <p>I have installed Python 2.6.4 and I don't think it has SSL support compiled into it. Is there a way to integrate this suppot into the newer python without having to install it again.</p>
  
  <p>I have installed OpenSSL and pyOpenSsl and I have tried the below code from one of the answers:</p>
  
  <pre><code>import urllib2
  from OpenSSL import SSL
  try: 
      response = urllib2.urlopen('https://example.com')  
      print 'response headers: "%s"' % response.info() 
  except IOError, e: 
      if hasattr(e, 'code'): # HTTPError 
          print 'http error code: ', e.code 
      elif hasattr(e, 'reason'): # URLError 
          print "can't connect, reason: ", e.reason 
      else: 
          raise
  </code></pre>
  
  <p>I have got an error:</p>
  
  <pre><code>    Traceback (most recent call last):
    File "&lt;stdin&gt;", line 2, in &lt;module&gt;
    File "/home/build/workspace/downloads/Python-2.6.4/Lib/urllib.py", line 87, in urlopen
      return opener.open(url)
    File "/home/build/workspace/downloads/Python-2.6.4/Lib/urllib.py", line 203, in open
      return self.open_unknown(fullurl, data)
    File "/home/build/workspace/downloads/Python-2.6.4/Lib/urllib.py", line 215, in open_unknown
      raise IOError, ('url error', 'unknown url type', type)
  IOError: [Errno url error] unknown url type: 'https'
  </code></pre>
  
  <p>Does anyone know how to get this working?</p>
  
  <pre><code>-- UPDATE
  </code></pre>
  
  <p>I have found out what the problem was, the Python version I was using did not have support for SSL. I have found this solution currently at: <a href="http://www.webtop.com.au/compiling-python-with-ssl-support" rel="noreferrer">http://www.webtop.com.au/compiling-python-with-ssl-support</a>. </p>
  
  <p>The code will now work after this solution which is very good. When I import ssl and HTTPSConnection I know don't get an error.</p>
  
  <p>Thanks for the help all.</p>