Python – Pip Install – Proxy Error – 'Cannot connect to proxy.', OSError'

Question:

I want to install some modules in a Enterprise VM in order to create some Python Scripts. I’m trying to use PIP with Proxy to do it. I’m using this command lines:

C:Usersuser>SET HTTPS_PROXY=https://user:[email protected]:8080

C:Usersuser>SET PROXY=http://user:[email protected]:8080

C:Usersuser>pip install datetime

To have access to my virtual machine I’ve this credentials:

  • USER: NAN/user
  • PASS: pass

But I am getting this error:

Collecting datetime
  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 Proxy Authentication Required ( Forefront TMG requires authorization to fulfill the request. Access to the Web Proxy filter is denied.  )',))': /simple/datetime/
  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 407 Proxy Authentication Required ( Forefront TMG requires authorization to fulfill the request. Access to the Web Proxy filter is denied.  )',))': /simple/datetime/
  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 407 Proxy Authentication Required ( Forefront TMG requires authorization to fulfill the request. Access to the Web Proxy filter is denied.  )',))': /simple/datetime/
  Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 407 Proxy Authentication Required ( Forefront TMG requires authorization to fulfill the request. Access to the Web Proxy filter is denied.  )',))': /simple/datetime/
  Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 407 Proxy Authentication Required ( Forefront TMG requires authorization to fulfill the request. Access to the Web Proxy filter is denied.  )',))': /simple/datetime/
  Could not find a version that satisfies the requirement datetime (from versions: )
No matching distribution found for datetime

What I need to do in order to get the python module?

Asked By: SaCvP

||

Answers:

Try like this:

set HTTP_PROXY=http://199.00.11.11:8080
set HTTPS_PROXY=https://199.00.11.11:8080
Answered By: Ankireddy

First, install a proxy authentication service like CNTLM)

Second,

set http_proxy=http://username:password@proxyAddress:port
set https_proxy=https://username:password@proxyAddress:port
Answered By: user8783223

I also faced this issue even with proxy, adding "–isolated" helped

For eg: pip install datetime –isolated

Note: My proxy is already set in "pip config"

Answered By: Mohit Sharma

I recently had a similar issue doing pip3 install awscli on my local mac. I checked my env and there were no proxies set there. The solution that worked for me was disabling proxies from the network which got set on my machine for some reason. To do that

  1. Click on Wifi
  2. Open Network Preferences
  3. Click Advanced button
  4. Go to proxies tab
  5. Uncheck Web Proxy and Secure Web Proxy

Again, I know that network proxy misconfiguration is rare and this answer may not be the most suitable answer. But this might come in useful for some folks as this is right now the first link that comes on google search for pip install ProxyError.

Answered By: Ankit Basarkar

If your proxy configration is OK,

It may be because your pip version is too high.
Try to lower your pip version

python -m pip install pip==19.3.1

Then restart your terminal.

You can try this method to see if it works

Answered By: boss zhu

In my case, it was only because the 【VPN】 software modified the 【System Proxy】 configuration of the 【IE】 browser.

I modified it back in this way:

  1. open 【IE】
  2. Press 【Alt+X】 and scroll down to 【Internet options】
  3. Click on the 【Connections】 tab
  4. Press the 【LAN settings】 button
  5. Uncheck the 【Proxy Server】

This is how my problem was successfully solved.

Answered By: Lancer.Yan

This works on Windows 10 for me:

  1. Search for Proxy Settings in Windows Start Search, open it

  2. Under Manual Proxy Setup, uncheck "Use a proxy server".

Alternatively, you may just add exceptions for the sources you want to install packages from.

Answered By: Suyash

Try like: Go to *control panel –> Internet options –> Connections –>LAN Settings ->mark ‘use proxy server for local address’ options.

Answered By: Andy

I ran into the same problem and the solution in my case was to unset the HTTPS_PROXY variable, because my proxy does not accept https requests.

I found the solution in this page : https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#https-proxy-error-http-proxy

All proxy variables are set by the os admin :

HTTP_PROXY=http://my_domain:8888
NO_PROXY=*.internal_domain,172.*,
HTTPS_PROXY=http://my_domain:8888

To update pip for example, I have to run :

unset HTTPS_PROXY ; pip install -U pip
Answered By: Alain Cherpin

Use the following code

pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org datetime

You can change datetime with the name of any package you want.

Answered By: Hadij
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.