如何禁用pip代理(不在shell导出中)?

2024-09-30 05:32:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用Mac,并尝试通过pip安装软件包:

(venv) ➜  ✗ pip install -r requirements.txt   
Collecting certifi==2019.9.11 (from -r requirements.txt (line 1))
http://127.0.0.1:6152
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x1041660d0>: Failed to establish a new connection: [Errno 61] Connection refused'))': /simple/certifi/
http://127.0.0.1:6152

我修改了pip的代码,以便它可以打印我使用的代理

venv/lib/python3.8/site-packages/pip-19.0.3-py3.8.egg/pip/_vendor/urllib3/connectionpool.pyurlopen方法:

        elif isinstance(e, (SocketError, NewConnectionError)) and self.proxy:
            print(self.proxy) # add this line
            e = ProxyError('Cannot connect to proxy.', e)

但我在我的export里什么也没找到:

(venv) ➜  ✗ export | grep proxy
(venv) ➜  ✗ 

那么,如何禁用我使用的代理(http://127.0.0.1:6152


Tags: piptotxtnonehttpvenvconnectline
1条回答
网友
1楼 · 发布于 2024-09-30 05:32:47

阅读代码后,我在/lib/python3.8/urllib/request.py中发现:

if sys.platform == 'darwin':
    from _scproxy import _get_proxy_settings, _get_proxies

    def proxy_bypass_macosx_sysconf(host):
        proxy_settings = _get_proxy_settings()
        return _proxy_bypass_macosx_sysconf(host, proxy_settings)

    def getproxies_macosx_sysconf():
        """Return a dictionary of scheme -> proxy server URL mappings.

        This function uses the MacOSX framework SystemConfiguration
        to fetch the proxy information.
        """
        return _get_proxies()



    def proxy_bypass(host):
        """Return True, if host should be bypassed.

        Checks proxy settings gathered from the environment, if specified,
        or from the MacOSX framework SystemConfiguration.

        """
        proxies = getproxies_environment()
        if proxies:
            return proxy_bypass_environment(host, proxies)
        else:
            return proxy_bypass_macosx_sysconf(host)

    def getproxies():
        return getproxies_environment() or getproxies_macosx_sysconf()

请注意:

def getproxies():
    return getproxies_environment() or getproxies_macosx_sysconf()

urllib从两个来源获取代理:

  1. 壳牌环境
  2. 系统设置

我调试过,它从sys得到了代理。所以我检查我的网络设置:

network settings

我找到了配置代理的地方

相关问题 更多 >

    热门问题