python corporate firewall proxy 407 authentication required error

Viewed 5950

I am behind a corporate firewall, while I can access the pypi website, I cannot install packages via pip. I get the 407 error:

"Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 407 authenticationrequired'))': /simple"

I tried various options like:

pip install --proxy=http://proxyhost:proxy_port PackageName which doesn't work

and even setting

http_proxy=http://username:password@proxyAddress:port https_proxy=https://username:password@proxyAddress:port

none of these work because of the corporate firewall. How can I install the packages?

2 Answers

After lot of struggling the easiest solution is:

  1. To visit the package website on pypi e.g. https://pypi.org/project/pyodbc/#files
  2. Find the relevant wheel, download it on your local machine
  3. Open command prompt and navigate to the location where the package is downloaded e.g. "C:\"
  4. Run pip install pyodbc-4.0.24-cp37-cp37m-win32.whl
  5. Voila the package should be installed

I had a similar issue and I was able to resolve it by installing a local cntlm proxy on my machine (which can be done even without admin permissions by simply downloading the .zip folder. You'll need to adapt the cntlm.ini file (insert the Username, Domain, Password (you can omit the password and enter it at startup), Proxy and Listen variables (see here for some more detailed instructions) and create a pip.ini-file in a folder named "pip" in your user directory (that worked for me, you might be able to put it somewhere else, too) with the following content

[global]
trusted-host = pypi.python.org
               pypi.org
               files.pythonhosted.org
proxy = # your local proxy address here (usually 127.0.0.1:3128)

After that, start the local proxy (I use a batch script) with path/to/your/cntlm.exe -c cntlm.ini -I -f and then pip should route your web requests to the local proxy which will then handle authentication at your corporate firewall for you.

With this setup, I am currently able to use any and all pip install-commands from behind the corporate firewall just fine

Related