Run easy_install pip under HTTPS proxy

Error:

bash-4.2$ export http_proxy=http://xxx:80

bash-4.2$ export https_proxy=https://xxx:80

bash-4.2$ which pip

which: no pip in (/usr/java/bin:/bin:/export/home/jacey/bin:/usr/ccs/bin:/usr/openwin/bin:.:/sbin:/usr/sbin:/usr/bin:/etc:/usr/ucb:/usr/dist/local/exe:/usr/dist/exe:/bin/X11:/usr/dt/bin:/usr/sadm/bin:/usr/local/bin)

bash-4.2$ sudo easy_install pip

Password:

Searching for pip

Reading https://pypi.python.org/simple/pip/

Download error on https://pypi.python.org/simple/pip/: [Errno 1] _ssl.c:504: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol — Some packages may not be found!

Couldn’t find index page for ‘pip’ (maybe misspelled?)

Scanning index of all packages (this may take a while)

Reading https://pypi.python.org/simple/

Download error on https://pypi.python.org/simple/: [Errno 1] _ssl.c:504: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol — Some packages may not be found!

No local packages or download links found for pip

error: Could not find suitable distribution for Requirement.parse(‘pip’)

bash-4.2$

Solution:

https://bitbucket.org/pypa/setuptools/issues/52/ssl-errors-with-https-proxy

https://bitbucket.org/pypa/setuptools/commits/8102f944d6af

    def connect(self):
        sock = create_connection(
            (self.host, self.port), getattr(self,'source_address',None)
        )

        # Handle the socket if a (proxy) tunnel is present
        if hasattr(self, '_tunnel') and getattr(self, '_tunnel_host', None):
            self.sock = sock
            self._tunnel()