Unable to install using PIP over proxy

2019-07-27 12:46发布

问题:

I have installed python over a custom location.

I am trying to install some packages however get the below error. I realized since I am on a VM and they are using proxy.

C:\python3.7>python -m pip install requests
Collecting requests
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x0424C6F0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /simple/requests/
  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x0426E150>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /simple/requests/
  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x0426E230>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /simple/requests/
  Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x0426E310>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /simple/requests/
  Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x0426E3F0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /simple/requests/
  Could not find a version that satisfies the requirement requests (from versions: )
No matching distribution found for requests

So I change the command to use the proxy. It clearly shows a certificate error so I contacted IT support and they have their own issues which is only frustrating.

C:\python3.7>python -m pip install requests --proxy=http://proxypac.novartis.net:2010
Collecting requests
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)'))': /simple/requests/
  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)'))': /simple/requests/
  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)'))': /simple/requests/
  Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)'))': /simple/requests/
  Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)'))': /simple/requests/
  Could not fetch URL https://pypi.org/simple/requests/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/requests/ (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)'))) - skipping
  Could not find a version that satisfies the requirement requests (from versions: )
No matching distribution found for requests
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)'))) - skipping

So I looked all over internet and tried to find to bypass this and tried.

Tried trusted host but didn't work out

C:\python3.7>python -m pip install --index-url=http://pypi.org/simple --trusted-host pypi.org --proxy=http://proxypac.novartis.net:2010 requests
Looking in indexes: http://pypi.org/simple
Collecting requests
  Could not find a version that satisfies the requirement requests (from versions: )
No matching distribution found for requests

Easy install with and without proxy

  C:\python3.7>python -m easy_install requests
    Searching for requests
    Reading https://pypi.org/simple/requests/
    Download error on https://pypi.org/simple/requests/: [Errno 11001] getaddrinfo failed -- Some packages may not be found!
    Couldn't find index page for 'requests' (maybe misspelled?)
    Scanning index of all packages (this may take a while)
    Reading https://pypi.org/simple/
    Download error on https://pypi.org/simple/: [Errno 11001] getaddrinfo failed -- Some packages may not be found!
    No local packages or working download links found for requests
    error: Could not find suitable distribution for Requirement.parse('requests')

        C:\python3.7>python -m easy_install requests --proxy=http://proxypac.novartis.net:2010
        Searching for requests
        Reading https://pypi.org/simple/requests/
        Download error on https://pypi.org/simple/requests/: [Errno 11001] getaddrinfo failed -- Some packages may not be found!
        Couldn't find index page for 'requests' (maybe misspelled?)
        Scanning index of all packages (this may take a while)
        Reading https://pypi.org/simple/
        Download error on https://pypi.org/simple/: [Errno 11001] getaddrinfo failed -- Some packages may not be found!
        No local packages or working download links found for requests
        error: Could not find suitable distribution for Requirement.parse('requests')

Trying to fetch from git

C:\python3.7>python -m pip install git+http://github.com/requests/requests.git
Collecting git+http://github.com/requests/requests.git
  Cloning http://github.com/requests/requests.git to c:\users\gargta2\appdata\local\temp\pip-req-build-dnz33avh
fatal: unable to access 'http://github.com/requests/requests.git/': Could not resolve host: github.com
Command "git clone -q http://github.com/requests/requests.git C:\Users\gargta2\AppData\Local\Temp\pip-req-build-dnz33avh" failed with error code 128 in None

Not even working with wheel file. That is ridiculous.

C:\python3.7>python -m pip install requests-2.21.0-py2.py3-none-any.whl
Processing c:\python3.7\requests-2.21.0-py2.py3-none-any.whl
Collecting idna<2.9,>=2.5 (from requests==2.21.0)
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x039C3D90>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /simple/idna/
  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x04567350>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /simple/idna/
  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x04567D10>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /simple/idna/
  Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x04567FD0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /simple/idna/
  Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x04545F70>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /simple/idna/
  Could not find a version that satisfies the requirement idna<2.9,>=2.5 (from requests==2.21.0) (from versions: )
No matching distribution found for idna<2.9,>=2.5 (from requests==2.21.0)

As suggested in comments by @hoefling trying another command but it fails :(

C:\python3.7>python -m pip install requests -vvv --index-url=https://pypi.org/simple --trusted-host=pypi.org --trusted-host=files.pythonhosted.org --proxy=http://proxypac.novartis.net:2010?
Config variable 'Py_DEBUG' is unset, Python ABI tag may be incorrect
Config variable 'WITH_PYMALLOC' is unset, Python ABI tag may be incorrect
Created temporary directory: C:\Users\gargta2\AppData\Local\Temp\pip-ephem-wheel-cache-3r4pn3eq
Created temporary directory: C:\Users\gargta2\AppData\Local\Temp\pip-req-tracker-h3p1whde
Created requirements tracker 'C:\\Users\\gargta2\\AppData\\Local\\Temp\\pip-req-tracker-h3p1whde'
Created temporary directory: C:\Users\gargta2\AppData\Local\Temp\pip-install-k9yyg7yl
Collecting requests
  1 location(s) to search for versions of requests:
  * https://pypi.org/simple/requests/
  Getting page https://pypi.org/simple/requests/
  Starting new HTTPS connection (1): pypi.org:443
  Incremented Retry for (url='/simple/requests/'): Retry(total=4, connect=None, read=None, redirect=None, status=None)
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)'))': /simple/requests/
  Starting new HTTPS connection (2): pypi.org:443
  Incremented Retry for (url='/simple/requests/'): Retry(total=3, connect=None, read=None, redirect=None, status=None)
  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)'))': /simple/requests/
  Starting new HTTPS connection (3): pypi.org:443
  Incremented Retry for (url='/simple/requests/'): Retry(total=2, connect=None, read=None, redirect=None, status=None)
  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)'))': /simple/requests/
  Starting new HTTPS connection (4): pypi.org:443
  Incremented Retry for (url='/simple/requests/'): Retry(total=1, connect=None, read=None, redirect=None, status=None)
  Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)'))': /simple/requests/
  Starting new HTTPS connection (5): pypi.org:443
  Incremented Retry for (url='/simple/requests/'): Retry(total=0, connect=None, read=None, redirect=None, status=None)
  Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)'))': /simple/requests/
  Starting new HTTPS connection (6): pypi.org:443
  Could not fetch URL https://pypi.org/simple/requests/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/requests/ (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)'))) - skipping
  Could not find a version that satisfies the requirement requests (from versions: )
Cleaning up...
Removed build tracker 'C:\\Users\\gargta2\\AppData\\Local\\Temp\\pip-req-tracker-h3p1whde'
No matching distribution found for requests
Exception information:
Traceback (most recent call last):
  File "C:\python3.7\lib\site-packages\pip\_internal\cli\base_command.py", line 143, in main
    status = self.run(options, args)
  File "C:\python3.7\lib\site-packages\pip\_internal\commands\install.py", line 318, in run
    resolver.resolve(requirement_set)
  File "C:\python3.7\lib\site-packages\pip\_internal\resolve.py", line 102, in resolve
    self._resolve_one(requirement_set, req)
  File "C:\python3.7\lib\site-packages\pip\_internal\resolve.py", line 256, in _resolve_one
    abstract_dist = self._get_abstract_dist_for(req_to_install)
  File "C:\python3.7\lib\site-packages\pip\_internal\resolve.py", line 209, in _get_abstract_dist_for
    self.require_hashes
  File "C:\python3.7\lib\site-packages\pip\_internal\operations\prepare.py", line 218, in prepare_linked_requirement
    req.populate_link(finder, upgrade_allowed, require_hashes)
  File "C:\python3.7\lib\site-packages\pip\_internal\req\req_install.py", line 164, in populate_link
    self.link = finder.find_requirement(self, upgrade)
  File "C:\python3.7\lib\site-packages\pip\_internal\index.py", line 621, in find_requirement
    'No matching distribution found for %s' % req
pip._internal.exceptions.DistributionNotFound: No matching distribution found for requests
Config variable 'Py_DEBUG' is unset, Python ABI tag may be incorrect
Config variable 'WITH_PYMALLOC' is unset, Python ABI tag may be incorrect
1 location(s) to search for versions of pip:
* https://pypi.org/simple/pip/
Getting page https://pypi.org/simple/pip/
Starting new HTTPS connection (1): pypi.org:443
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)'))) - skipping

Also tried other methods 1. changing http with https 2. I don't see any pip.ini file but none seem to be working.

回答1:

Since your Networks firewall is blocking your access, you will need to tunnel your pip request, this link can help Connect to VPN by Powershell, after that you should be able to tunnel your Pip requests through, there are multiple VPN providers that you can use which allow passthrough connections, My Recommendations are NordVPN and DotVPN.

If you have additional queries about tunneling your connection through VPN you can have a look here https://docs.microsoft.com/en-us/powershell/module/vpnclient/add-vpnconnection?view=win10-ps.

Also if your networks firewall is blocking accessing to PyPi, they are most likely to block access to VPN, so I would recommend testing if the VPN you are trying to tunnel through is not blocked by your IP. There is an alternative to curl known as bitsadmin that you can use to verify if you have access to the vpn, or just use old fashioned ping.

P.S. Both the VPN's have free tier and that is what I recommend.

If it still doesn't work, comment down with the error.