Using Pip Behind a Proxy with Cntlm

Using pip behind a proxy with CNTLM

To setup CNTLM for windows, follow this article. For Ubuntu, read my blog post.

Edit:

Basically, to use CNTLM in any platform, you need to setup your username and hashed password, before using http://127.0.0.1:3128 as a proxy to your parent proxy.

  1. Edit the config and add important information like domain, username, password and parent proxy.

  2. Generate hashed password.

    Windows cntlm –c cntlm.ini –H

    Ubuntu/Linux cntlm -v -H -c /etc/cntlm.conf

  3. Remove plain text password from the config and replace them with the generated passwords.

To check if working:

Windows cntlm –M http://www.google.com

Ubuntu/Linux sudo cntlm -M http://www.google.com/

For more detailed instructions, see links above.

Update:

Just for completeness sake, I was able to configure and use CNTLM in Windows recently. I encountered a problem during the syncing process of Kindle for PC because of our proxy and installing and configuring CNTLM for Windows fixed that issue for me. Refer to my article for more details.

How to use pip on windows behind an authenticating proxy

I have tried 2 options which both work on my company's NTLM authenticated proxy.
Option 1 is to use --proxy http://user:pass@proxyAddress:proxyPort

If you are still having trouble I would suggest installing a proxy authentication service (I use CNTLM) and pointing pip at it ie something like --proxy http://localhost:3128

Using pip behind a proxy with CNTLM

To setup CNTLM for windows, follow this article. For Ubuntu, read my blog post.

Edit:

Basically, to use CNTLM in any platform, you need to setup your username and hashed password, before using http://127.0.0.1:3128 as a proxy to your parent proxy.

  1. Edit the config and add important information like domain, username, password and parent proxy.

  2. Generate hashed password.

    Windows cntlm –c cntlm.ini –H

    Ubuntu/Linux cntlm -v -H -c /etc/cntlm.conf

  3. Remove plain text password from the config and replace them with the generated passwords.

To check if working:

Windows cntlm –M http://www.google.com

Ubuntu/Linux sudo cntlm -M http://www.google.com/

For more detailed instructions, see links above.

Update:

Just for completeness sake, I was able to configure and use CNTLM in Windows recently. I encountered a problem during the syncing process of Kindle for PC because of our proxy and installing and configuring CNTLM for Windows fixed that issue for me. Refer to my article for more details.

pip behind a company proxy - workaround?

Install the packages from PyPI as follows:

  • Download the package
  • Unzip it
  • Go into the folder with setup.py
  • type in python setup.py install (if not stated otherwise in the installation instructions)

Another way is to use the Windows binaries for Python which can be found at ~gohlke. Install the downloaded wheels via pip install some-package.whl.


A solution for your proxy issue could be to look up the IP addresses used by the load-balancer of the proxy (usually listed in the .pac file, try to open it directly in a web browser) and set one of the proxy IPs manually in the Internet Explorer settings and in your pip or Python settings. Usually the company IT rules reset the proxy settings quite often, so you have to do this every time, you hit the proxy error.

Run inetcpl.cpl ,4 to open the Internet Explorer settings directly on the tab you need to set the proxy.

How to configure PIP per config file to use a proxy (with authentification)?

Here are the steps how to configure proxy (with auth.) in pip's config file (pip.ini)

  1. (if it does not already exist) Create a folder named 'pip' and inside it a file named 'pip.ini' as described here: https://pip.pypa.io/en/stable/user_guide/#config-file (location an name may differ per platform - e.g. on Windows it's %APPDATA%\pip\pip.ini)
  2. edit pip.ini file and add

    [global]
    proxy = http://user:password@proxy_name:port
  3. That's it!

Example for proxy with authentification (user + password):

proxy = http://butch:secret@proxyname:1234

proxyname can be an IP adress, too

Example for proxy without auth.:

proxy = http://proxyname:1234

Can't use CNTLM to connect to pip

I have had the exact same issue.

Cntlm is used for authentication proxy servers, these statements mean that your server does not require authentication.

The pip command does have a --proxy option. Try using something like:

pip install --proxy=10.0.0.1:80 package_name

If this works, you know that you don't need authentication to access the web. If it still fails try:

pip install --proxy=user:password@10.0.0.1:80 package_name

This works to get around authentication. I have written a small cmd script to get around this in windows:

@echo off
:: GetPwd.cmd - Get password with no echo.
setlocal
<nul: set /p passwd=
for /f "delims=" %%i in ('python -c "from getpass import getpass; pwd = getpass();print pwd;"') do set passwd=%%i
echo.

::Prompt for the package name
set /p package=What package would you like to get:

::Get the package with PIP
pip install --proxy="admin:%passwd%@PROXY_ADDRESS:80" %package%
endlocal


Related Topics



Leave a reply



Submit