Skip to content

Proxy being used even though NO_PROXY env var is set (while pip config file has proxy defined) #12610

Closed as not planned
@yaronyudov

Description

@yaronyudov

Description

I have a requirements.txt file containing both libraries from pypi.org and my personal repository.
Note that for accessing pypi.org I need to use a proxy and for my personal repository I must not use a proxy.

I understand according to the precedence-override-order env var should override configs that are defined from pip config

I used pip config set command to set:

  • install.proxy
  • install.trusted-host
  • install.extra-index-url

My pip.ini file looks like this
[install]
proxy = http://proxy host:port
trusted-host = my.repository
extra-index-url = https://my.repository/simple

My packages from pypi were installed but my personal lib from my personal repository wasn't.
I inspected the logs (ran with -vvv flag) and noticed that the connection had an error - something to do with a proxy (which I expect wouldn't be used at all).

I debugged the install command (pip 24.0 and 23.2.1) and both had the same issue.
I noticed a proxy was being used for my personal repository (even though the hostname is defined within my NO_PROXY env var).

The proxy was set within python source file pip\_vendor\requests\adapters.py
Method def get_connection(self, url, proxies=None):, code -> proxy = select_proxy(url, proxies)

Expected behavior

Expected NO_PROXY env var respected over pip config file
Meaning, proxy not used for my python repository but for others only

pip version

24.0, 23.2.1

Python version

3.9

OS

Windows

How to Reproduce

  1. Setup a python repository
  2. Install any package in that repository
  3. Setup a proxy that blocks direct calls to pypi (but has access on its own to pypi) and has no access to your repository (but you must have access to it from your machine)
  4. Create requirements.txt file that contains packages both pypi and your repository
  5. Run pip config set install.proxy = proxy
  6. Run pip config set install.trusted-host= custom.repository.hostname
  7. Run pip config set install.extra-index-url = https://custom.repository.hostname/simple
  8. Run pip install -vvv -r requirements.txt

Output

...
Could not fetch URL https://my.repository:port/simple/my-package/: connection error: HTTPSConnectionPool(host='my.repository', port=port): Max retries exceeded with url: /simple/my-package/ (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 403 Tunnel or SSL Forbidden'))) - skipping
...

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions