title: Pip install/upgrade error, will not install or upgrade anything, odd traceback
body: <p><code>Python Version=2.6.6</code></p>
  
  <p>Ok, so this one has me stumped.  </p>
  
  <p>First off, here is the traceback for when I try to install something.  In this case I ran: <code>pip install requests</code>
  as root. NOTE: I am aware this is pip version <code>7.0.3</code>.  The same traceback appears with the latest version of pip.  </p>
  
  <pre><code>Traceback (most recent call last):
    File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/basecommand.py", line 223, in main
      status = self.run(options, args)
    File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/commands/install.py", line 291, in run
      wb.build(autobuilding=True)
    File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/wheel.py", line 705, in build
      self.requirement_set.prepare_files(self.finder)
    File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/req/req_set.py", line 317, in prepare_files
      functools.partial(self._prepare_file, finder))
    File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/req/req_set.py", line 304, in _walk_req_to_install
      more_reqs = handler(req_to_install)
    File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/req/req_set.py", line 439, in _prepare_file
      req_to_install.populate_link(finder, self.upgrade)
    File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/req/req_install.py", line 244, in populate_link
      self.link = finder.find_requirement(self, upgrade)
    File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/index.py", line 486, in find_requirement
      all_versions = self._find_all_versions(req.name)
    File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/index.py", line 404, in _find_all_versions
      index_locations = self._get_index_urls_locations(project_name)
    File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/index.py", line 378, in _get_index_urls_locations
      page = self._get_page(main_index_url)
    File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/index.py", line 810, in _get_page
      return HTMLPage.get_page(link, session=self.session)
    File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/index.py", line 920, in get_page
      "Cache-Control": "max-age=600",
    File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/_vendor/requests/sessions.py", line 477, in get
      return self.request('GET', url, **kwargs)
    File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/download.py", line 373, in request
      return super(PipSession, self).request(method, url, *args, **kwargs)
    File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/_vendor/requests/sessions.py", line 465, in request
      resp = self.send(prep, **send_kwargs)
    File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/_vendor/requests/sessions.py", line 573, in send
      r = adapter.send(request, **kwargs)
    File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/_vendor/cachecontrol/adapter.py", line 46, in send
      resp = super(CacheControlAdapter, self).send(request, **kw)
    File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/_vendor/requests/adapters.py", line 370, in send
      timeout=timeout
    File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 544, in urlopen
      body=body, headers=headers)
    File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 341, in _make_request
      self._validate_conn(conn)
    File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 761, in _validate_conn
      conn.connect()
    File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/_vendor/requests/packages/urllib3/connection.py", line 238, in connect
      ssl_version=resolved_ssl_version)
    File "/usr/lib/python2.6/site-packages/pip-7.0.3-py2.6.egg/pip/_vendor/requests/packages/urllib3/contrib/pyopenssl.py", line 279, in ssl_wrap_socket
      cnx.set_tlsext_host_name(server_hostname)
  AttributeError: '_socketobject' object has no attribute 'set_tlsext_host_name'
  </code></pre>
  
  <p>I then uninstalled pip using <code>pip uninstall pip</code>and confirmed that the egg and binary files were removed.  Then I reinstalled it using <code>easy_install pip</code> but no luck.  I also tried this again but with the latest version of pip and version <code>7.0.3</code>.  Same thing.</p>
  
  <p>Also, installing <code>get-pip.py</code> gives this traceback, which is oddly similar:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/tmp/tmp0rv6P1/pip.zip/pip/basecommand.py", line 223, in main
      status = self.run(options, args)
    File "/tmp/tmp0rv6P1/pip.zip/pip/commands/install.py", line 291, in run
      wb.build(autobuilding=True)
    File "/tmp/tmp0rv6P1/pip.zip/pip/wheel.py", line 705, in build
      self.requirement_set.prepare_files(self.finder)
    File "/tmp/tmp0rv6P1/pip.zip/pip/req/req_set.py", line 317, in prepare_files
      functools.partial(self._prepare_file, finder))
    File "/tmp/tmp0rv6P1/pip.zip/pip/req/req_set.py", line 304, in _walk_req_to_install
      more_reqs = handler(req_to_install)
    File "/tmp/tmp0rv6P1/pip.zip/pip/req/req_set.py", line 387, in _prepare_file
      req_to_install, finder)
    File "/tmp/tmp0rv6P1/pip.zip/pip/req/req_set.py", line 348, in _check_skip_installed
      finder.find_requirement(req_to_install, self.upgrade)
    File "/tmp/tmp0rv6P1/pip.zip/pip/index.py", line 486, in find_requirement
      all_versions = self._find_all_versions(req.name)
    File "/tmp/tmp0rv6P1/pip.zip/pip/index.py", line 404, in _find_all_versions
      index_locations = self._get_index_urls_locations(project_name)
    File "/tmp/tmp0rv6P1/pip.zip/pip/index.py", line 378, in _get_index_urls_locations
      page = self._get_page(main_index_url)
    File "/tmp/tmp0rv6P1/pip.zip/pip/index.py", line 810, in _get_page
      return HTMLPage.get_page(link, session=self.session)
    File "/tmp/tmp0rv6P1/pip.zip/pip/index.py", line 920, in get_page
      "Cache-Control": "max-age=600",
    File "/tmp/tmp0rv6P1/pip.zip/pip/_vendor/requests/sessions.py", line 477, in get
      return self.request('GET', url, **kwargs)
    File "/tmp/tmp0rv6P1/pip.zip/pip/download.py", line 373, in request
      return super(PipSession, self).request(method, url, *args, **kwargs)
    File "/tmp/tmp0rv6P1/pip.zip/pip/_vendor/requests/sessions.py", line 465, in request
      resp = self.send(prep, **send_kwargs)
    File "/tmp/tmp0rv6P1/pip.zip/pip/_vendor/requests/sessions.py", line 573, in send
      r = adapter.send(request, **kwargs)
    File "/tmp/tmp0rv6P1/pip.zip/pip/_vendor/cachecontrol/adapter.py", line 46, in send
      resp = super(CacheControlAdapter, self).send(request, **kw)
    File "/tmp/tmp0rv6P1/pip.zip/pip/_vendor/requests/adapters.py", line 370, in send
      timeout=timeout
    File "/tmp/tmp0rv6P1/pip.zip/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 544, in urlopen
      body=body, headers=headers)
    File "/tmp/tmp0rv6P1/pip.zip/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 341, in _make_request
      self._validate_conn(conn)
    File "/tmp/tmp0rv6P1/pip.zip/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 761, in _validate_conn
      conn.connect()
    File "/tmp/tmp0rv6P1/pip.zip/pip/_vendor/requests/packages/urllib3/connection.py", line 238, in connect
      ssl_version=resolved_ssl_version)
    File "/tmp/tmp0rv6P1/pip.zip/pip/_vendor/requests/packages/urllib3/contrib/pyopenssl.py", line 279, in ssl_wrap_socket
      cnx.set_tlsext_host_name(server_hostname)
  AttributeError: '_socketobject' object has no attribute 'set_tlsext_host_name'
  </code></pre>
  
  <p>What really has me confused is the last 4 lines of the traceback.  After analyzing the traceback I dove into the pip egg. </p>
  
  <p>Obviously from the traceback, the error is coming from the <code>ssl_wrap_socket</code> function, which is called in <code>connection.py</code>.  The traceback says that <code>ssl_wrap_socket</code> called is defined in <code>{urlib3_path}/contrib/pyopenssl.py</code>, but, upon looking at lines <code>45-50</code> of <code>connection.py</code>:</p>
  
  <pre><code># connection.py
       from .util.ssl_ import (
           resolve_cert_reqs,
           resolve_ssl_version,
           ssl_wrap_socket,
           assert_fingerprint,
       )
  </code></pre>
  
  <p><code>ssl_wrap_socket</code> should be importing from <code>{urllib3_path}/util/ssl_.py</code> which does not contain the offending line of code, but according to the traceback that is not what is happening.</p>
  
  <p>I have no idea what is going but assume this is some subtly about python I am unaware of.  If anyone has any clue please let me know.  </p>
  
  <p>Edit: New development!</p>
  
  <p>Upon stumbling onto <a href="https://github.com/kennethreitz/requests/blob/a57c87a459d51c5b17d20285109e901b8aa95752/requests/__init__.py#L54" rel="nofollow">this bit of the requests code</a> from github it appears that the requests library actually injects <code>pyopenssl</code> into the urllib3 library which explains the traceback.  However I am still unsure of how to fix this.  </p>
  
  <p>Edit2: Solution!</p>
  
  <p>Turns out the urllib3 library was being injected with the wrong <code>pyopenssl</code> !  After I found out that requests was injecting <code>pyopenssl</code> into the <code>urllib3</code> library I checked out <code>pyopenssl.py</code> and found this function: </p>
  
  <pre><code>def inject_into_urllib3():
      'Monkey-patch urllib3 with PyOpenSSL-backed SSL-support.'
  
      connection.ssl_wrap_socket = ssl_wrap_socket
      util.HAS_SNI = HAS_SNI
  </code></pre>
  
  <p><code>ssl_wrap_socket</code> is defined in <code>pyopenssl.py</code> and relies on <code>OpenSSL.SSL</code>.  </p>
  
  <p>I hopped on over to <code>pyOpenSSL-0.15.1-py2.6.egg</code> in the <code>site-packages</code> folder and just to be sure checked the version, which was <code>0.15.1</code>.  After some pondering I opened up the interpreter and ran</p>
  
  <pre><code>&gt;&gt;&gt; import OpenSSL.SSL as ssl
  &gt;&gt;&gt; ssl.__file__
  </code></pre>
  
  <p>Which told me I had an OpenSSL directory in <code>lib64/python2.6/site-packages</code> that was being referenced rather than the <code>OpenSSL</code> directory in the <code>pyOpenSSL</code> egg, and it was only version <code>0.10</code>!  which of course what was causing the original error to be thrown.  After removing that directory Pip seems to be running without issue.</p>