title: wrap_socket() got an unexpected keyword argument 'server_hostname'?
body: <p>I'm trying to use Python to test a web server. I have nearly no experience with Python, but encouraged to use it because its easy to learn and simple to do things with (someone else's opinion, not mine at the moment). The script I am using is:</p>
  
  <pre><code>s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  s2 = ssl.wrap_socket(s1,
                       ca_certs="./pki/signing-dss-cert.pem",
                       cert_reqs=ssl.CERT_REQUIRED,
                       ssl_version=ssl.PROTOCOL_TLSv1,
                       server_hostname="localhost")
  
  s2.connect( ("localhost", 8443) )
  
  s2.send("GET / ")
  time.sleep(1)
  s2.send("HTTP/1.1")
  </code></pre>
  
  <p>The error is:</p>
  
  <pre><code>Traceback (most recent call last):
    File "./fetch.sh", line 10, in &lt;module&gt;
      server_hostname="localhost")
  TypeError: wrap_socket() got an unexpected keyword argument 'server_hostname'
  </code></pre>
  
  <p>I've also tried using <code>servername</code>, <code>name</code>, <code>hostname</code> and <code>sni</code> with no joy.</p>
  
  <p>The Python docs don't mention SNI (<a href="http://docs.python.org/3/library/ssl.html" rel="nofollow">TLS/SSL wrapper for socket objects</a> and <a href="https://wiki.python.org/moin/SSL" rel="nofollow">SSL wiki page</a>). But I know the patch for SNI and <code>server_hostname</code> was incorporated 4 years ago in 2010 (<a href="http://hg.python.org/cpython/rev/846c0e1342d0/" rel="nofollow">Add a *server_hostname* argument to <code>SSLContext.wrap_socket</code></a>, <a href="http://hg.python.org/cpython/rev/846c0e1342d0/" rel="nofollow">changeset 65593:846c0e1342d0</a>).</p>
  
  <p>The equivalent OpenSSL call I need access to is <code>SSL_set_tlsext_host_name</code>.</p>
  
  <p>How do I specify the SNI hostname? (Eventually, I'll need to set it to an arbitrary name because I am testing a proxy).</p>