Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pip ignores proxy settings except ones defined in environment variables #9105

Open
wingsoflight opened this issue Nov 5, 2020 · 23 comments
Open
Labels
C: proxy Dealing with proxies and networking state: needs eyes Needs a maintainer/triager to take a closer look

Comments

@wingsoflight
Copy link

wingsoflight commented Nov 5, 2020

Environment

  • pip version: 20.1.1
  • Python version: 3.7.9
  • OS: Windows 10

Clean installed OS with official python binaries.

Description

I have a clean Windows 10 OS with installed offical python==3.7.9 binaries. When I tried to install packages via pip, I encountered problem with proxy settings which was written in pip.ini, that pip seems to be ignore it. I also tried to pass config with corresponding --proxy option, but similarly it do not affected to pip's behavior. Only proxy settings written to HTTP_PROXY or HTTPS_PROXY evs was accepted.

Expected behavior

To be able download a packages from pypi if proxy settings well defined in any source which were pointed in documentation.

How to Reproduce

  1. Preferibly have a clean OS install behind proxy.
  2. Download python binaries installer (In my case 3.7.9)
  3. Install it with "add to PATH" option checked.
  4. In %APPDATA% directory make folder called pip
  5. create pip.ini inside it and define your proxy settings as described in documentation.
  6. run pip config list to ensure that your configs have been read succesfully.
  7. run pip install <package> without setting HTTP_PROXY or HTTPS_PROXY environment variables.
  8. try to directly pass config with --proxy option.

Output

WARNING: 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'))': /simple/numpy/
WARNING: 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'))': /simple/numpy/
WARNING: 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'))': /simple/numpy/
WARNING: 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'))': /simple/numpy/
WARNING: 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'))': /simple/numpy/
@danielhrisca
Copy link

I second this problem:

image

Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32

@stonecharioteer
Copy link

Can you print out your config with
pip config list

@danielhrisca
Copy link

Can you print out your config with
pip config list

On my PC I get no output for this command

@wingsoflight
Copy link
Author

Can you print out your config with
pip config list

:env:.disable-pip-version-check='1'
:env:.python-path='some path to python 3.7 executable'
global.http-proxy='http://<IP>:<port>'
global.https-proxy='http://<IP>:<port>'
global.proxy='http://<IP>:<port>'

@stonecharioteer
Copy link

stonecharioteer commented Nov 19, 2020

@danielhrisca If you get no output, then your pip config is not in the right folder. Please refer the Windows steps here. Also, ensure you're using pip > 18. Preferably, the latest version.

@wingsoflight That is strange.

@danielhrisca
Copy link

@stonecharioteer I will have this in mind in future, but I think things should work even if you don't have a config setup up right?

@stonecharioteer
Copy link

@danielhrisca unless you're in a corporate network with proxies being needed.

@danielhrisca
Copy link

I don't understand why pip can't use/forward the proxy given in the command line invocation using the --proxy argument

@stonecharioteer
Copy link

stonecharioteer commented Nov 19, 2020

Oh I misread your question. Yes, it should. That's why the argument exists.
What happens when you set HTTP_PROXY and HTTPS_PROXY?

By the way, when you do this, I recommend setting even the http_proxy and https_proxy envvars as well. Some applications use the lowercase variables.

@danielhrisca
Copy link

I always use the --proxy argument.
The problem occurs if a package has a build dependencies. The invocation for installing them will not receive the proxy argument. If I set up the environment variable HTTPS_PROXY the it works.

@danielhrisca
Copy link

I could also add that even though setuptools is already installed , the "installing build dependencies" step is still triggered

@wingsoflight
Copy link
Author

wingsoflight commented Nov 20, 2020

@wingsoflight That is strange.

I think its because of using the requests package.

@xavfernandez
Copy link
Member

I always use the --proxy argument.
The problem occurs if a package has a build dependencies. The invocation for installing them will not receive the proxy argument. If I set up the environment variable HTTPS_PROXY the it works.

This would be a case of #7805

@pradyunsg pradyunsg added C: proxy Dealing with proxies and networking state: needs eyes Needs a maintainer/triager to take a closer look labels Dec 1, 2020
@junqfisica
Copy link
Contributor

Problem-related pypa/pip#9691. Fix will be applied by the commit discussed here , on the requests end.

@ByteJuggler
Copy link

ByteJuggler commented Feb 4, 2022

Ran into this again today (--proxy not being respected):
image
Requests etc versions:
image

@kevingoos
Copy link

kevingoos commented Jun 16, 2022

I also had the problem, where if set HTTP_PROXY and HTTPS_PROXY on powershell, it was not working.
But when I add it to the user environment variables or use the --proxy parameter in the command, it works.

So I set it now in the user environment variables and it is solved for me, but wanted to let you guys know.

  • Python 3.10.5
  • pip 22.0.4

@junqfisica
Copy link
Contributor

First I would like to point out that for pip >= 22.1 the --proxy keyword should be working as a result of this merge.

@kevingoos Be careful with set HTTP_PROXY in PowerShell it DOES NOT WORK as in the CMD. Instead you should use [System.Environment]::SetEnvironmentVariable("HTTPS_PROXY ", "your_proxy")

@q0w

This comment was marked as off-topic.

@ByteJuggler
Copy link

ByteJuggler commented Jun 16, 2022 via email

@Drackrath
Copy link

Drackrath commented May 22, 2023

Any update to this? I experience the same issue.

@andrewchenshx
Copy link

windows10, settings->network&internet->proxy->Use a proxy server,
if this option is on, then Connection to pypi.org time out, even if --proxy=http://: is added to the command.
if toggled off, then it works with --proxy=http://: added to the command.

the ip and port are exactly same as the ones set in the system setting( settings->network&internet->proxy->Use a proxy server).

@junqfisica
Copy link
Contributor

@andrewchenshx
Please, check this comment carefully: #9105 (comment). Make sure you have the latest pip version installed. Also, I would like to point out that this problem is not entirely from Pip but a behavior issue on the requests package see warning..

I hope this helps to clarify the issue. :)

@travishsu
Copy link

I experienced this issue too. I downgrade pip from 23.3.2 to 21.3.1 then this issue disappeared.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: proxy Dealing with proxies and networking state: needs eyes Needs a maintainer/triager to take a closer look
Projects
None yet
Development

No branches or pull requests