pip can be configured to connect through a proxy server in various ways: using the --proxy command-line option to specify a proxy in the form scheme://[user:passwd@]proxy.server:port. using proxy in a Configuration Files. by setting the standard environment-variables http_proxy , https_proxy and no_proxy .
A proxy server for pip is most commonly used for security and privacy, but can also be used for control: Security & Privacy – a proxy server can be used in combination with firewalls in order to improve internal network security since requests from users on the local network are anonymized via a proxy server.
To use a proxy in Python, first import the requests package. Next create a proxies dictionary that defines the HTTP and HTTPS connections. This variable should be a dictionary that maps a protocol to the proxy URL. Additionally, make a url variable set to the webpage you're scraping from.
With Ubuntu I could not get the proxy option to work as advertised – so following command did not work:
sudo pip --proxy http://web-proxy.mydomain.com install somepackage
But exporting the https_proxy
environment variable (note its https_proxy
not http_proxy
) did the trick:
export https_proxy=http://web-proxy.mydomain.com
then
sudo -E pip install somepackage
Under Windows dont forget to set
SET HTTPS_PROXY=<proxyHost>:<proxyPort>
what I needed to set for
pip install pep8
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.
Edit the config and add important information like domain, username, password and parent proxy.
Generate hashed password.
Windows cntlm –c cntlm.ini –H
Ubuntu/Linux cntlm -v -H -c /etc/cntlm.conf
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.
It was not working for me. I had to use https at work:
pip install --proxy=https://user@mydomain:port somepackage
In order to update, add -U.
You can continue to use pip over HTTPS by adding your corporation's root certificate to the cacert.pem file in your site-packages/pip folder. Then configure pip to use your proxy by adding the following lines to ~/pip/pip.conf (or ~\pip\pip.ini if you're on Windows):
[global]
proxy = [user:passwd@]proxy.server:port
That's it. No need to use third party packages or give up HTTPS (of course, your network admin can still see what you're doing).
for windows; set your proxy in command prompt asset HTTP_PROXY=domain\username:password@myproxy:myproxyport
example: set http_proxy=IND\namit.kewat:[email protected]:8880
This worked for me (on Windows via CMD):
pip install --proxy proxyserver:port requests
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With