18

尝试在新的 python 安装上安装 pip。我被代理错误困住了。看起来像一个错误get-pipurllib3??

问题是我是否必须像这里描述的那样经历设置 CNTLM 的痛苦,还是有捷径?

get-pip.py 文档说使用--proxy="[user:passwd@]proxy.server:port"选项来指定代理和相关身份验证。但似乎 pip 传递了整个事情,因为它将urllib3“myusr”解释为 url 方案,因为我猜是':'(?)。

C:\ProgFiles\Python27>get-pip.py --proxy myusr:mypswd@111.222.333.444:80
Downloading/unpacking pip
Cleaning up...
Exception:
Traceback (most recent call last):
  File "c:\users\sg0219~1\appdata\local\temp\tmpxwg_en\pip.zip\pip\basecommand.py", line 122, in main
    status = self.run(options, args)
  File "c:\users\sg0219~1\appdata\local\temp\tmpxwg_en\pip.zip\pip\commands\install.py", line 278, in run
    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
  File "c:\users\sg0219~1\appdata\local\temp\tmpxwg_en\pip.zip\pip\req.py", line 1177, in prepare_files
    url = finder.find_requirement(req_to_install, upgrade=self.upgrade)
  File "c:\users\sg0219~1\appdata\local\temp\tmpxwg_en\pip.zip\pip\index.py", line 194, in find_requirement
    page = self._get_page(main_index_url, req)
  File "c:\users\sg0219~1\appdata\local\temp\tmpxwg_en\pip.zip\pip\index.py", line 568, in _get_page
    session=self.session,
  File "c:\users\sg0219~1\appdata\local\temp\tmpxwg_en\pip.zip\pip\index.py", line 670, in get_page
    resp = session.get(url, headers={"Accept": "text/html"})
  File "c:\users\sg0219~1\appdata\local\temp\tmpxwg_en\pip.zip\pip\_vendor\requests\sessions.py", line 468, in get
    return self.request('GET', url, **kwargs)
  File "c:\users\sg0219~1\appdata\local\temp\tmpxwg_en\pip.zip\pip\download.py", line 237, in request
    return super(PipSession, self).request(method, url, *args, **kwargs)
  File "c:\users\sg0219~1\appdata\local\temp\tmpxwg_en\pip.zip\pip\_vendor\requests\sessions.py", line 456, in request
    resp = self.send(prep, **send_kwargs)
  File "c:\users\sg0219~1\appdata\local\temp\tmpxwg_en\pip.zip\pip\_vendor\requests\sessions.py", line 559, in send
    r = adapter.send(request, **kwargs)
  File "c:\users\sg0219~1\appdata\local\temp\tmpxwg_en\pip.zip\pip\_vendor\requests\adapters.py", line 305, in send
    conn = self.get_connection(request.url, proxies)
  File "c:\users\sg0219~1\appdata\local\temp\tmpxwg_en\pip.zip\pip\_vendor\requests\adapters.py", line 215, in get_connection
    block=self._pool_block)
  File "c:\users\sg0219~1\appdata\local\temp\tmpxwg_en\pip.zip\pip\_vendor\requests\packages\urllib3\poolmanager.py", line 258, in proxy_fro
m_url
    return ProxyManager(proxy_url=url, **kw)
  File "c:\users\sg0219~1\appdata\local\temp\tmpxwg_en\pip.zip\pip\_vendor\requests\packages\urllib3\poolmanager.py", line 214, in __init__
    'Not supported proxy scheme %s' % self.proxy.scheme
AssertionError: Not supported proxy scheme myusr

Storing debug log for failure in C:\Users\myusr\pip\pip.log

C:\ProgFiles\Python27>

当我在没有 usrname 和密码的情况下运行命令时,它可以正常工作,但代理拒绝请求说它需要身份验证(“需要 407 身份验证”)。

C:\ProgFiles\Python27>get-pip.py --proxy 111.222.333.444:80
Downloading/unpacking pip
  Cannot fetch index base URL https://pypi.python.org/simple/
  Could not find any downloads that satisfy the requirement pip
Cleaning up...
No distributions at all found for pip
Storing debug log for failure in C:\Users\sg0219898\pip\pip.log

C:\ProgFiles\Python27>cat C:\Users\sg0219898\pip\pip.log
------------------------------------------------------------
C:\ProgFiles\Python27\get-pip.py run on 09/29/14 16:23:26
Downloading/unpacking pip
  Getting page https://pypi.python.org/simple/pip/
  Could not fetch URL https://pypi.python.org/simple/pip/: connection error: ('Cannot connect to proxy.', error('Tunnel connection failed: 407 authenticationrequired',))
  Will skip URL https://pypi.python.org/simple/pip/ when looking for download links for pip
  Getting page https://pypi.python.org/simple/
  Could not fetch URL https://pypi.python.org/simple/: connection error: ('Cannot connect to proxy.', error('Tunnel connection failed: 407 authenticationrequired',))
  Will skip URL https://pypi.python.org/simple/ when looking for download links for pip
  Cannot fetch index base URL https://pypi.python.org/simple/
  URLs to search for versions for pip:
  * https://pypi.python.org/simple/pip/
  Getting page https://pypi.python.org/simple/pip/
  Could not fetch URL https://pypi.python.org/simple/pip/: connection error: ('Cannot connect to proxy.', error('Tunnel connection failed: 407 authenticationrequired',))
  Will skip URL https://pypi.python.org/simple/pip/ when looking for download links for pip
  Could not find any downloads that satisfy the requirement pip
Cleaning up...
  Removing temporary dir c:\users\sg0219~1\appdata\local\temp\pip_build_SG0219898...
No distributions at all found for pip
Exception information:
Traceback (most recent call last):
  File "c:\users\sg0219~1\appdata\local\temp\tmp36ynxd\pip.zip\pip\basecommand.py", line 122, in main
    status = self.run(options, args)
  File "c:\users\sg0219~1\appdata\local\temp\tmp36ynxd\pip.zip\pip\commands\install.py", line 278, in run
    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
  File "c:\users\sg0219~1\appdata\local\temp\tmp36ynxd\pip.zip\pip\req.py", line 1177, in prepare_files
    url = finder.find_requirement(req_to_install, upgrade=self.upgrade)
  File "c:\users\sg0219~1\appdata\local\temp\tmp36ynxd\pip.zip\pip\index.py", line 277, in find_requirement
    raise DistributionNotFound('No distributions at all found for %s' % req)
DistributionNotFound: No distributions at all found for pip

C:\ProgFiles\Python27>

我看了一眼,urllib3\poolmanager.py它似乎与用户名/密码没有任何关系。

4

9 回答 9

25

这是在抱怨 URL 的方案(urlparse理解为 be myusr),以解决您应该这样做的问题:

get-pip.py --proxy http://myusr:mypswd@111.222.333.444:80
于 2014-09-30T14:22:40.637 回答
8

这是因为脚本需要环境变量 http_proxy 或 https_proxy 包含 URL 中的方案。设置环境变量

 export http_proxy="http://<hostname>:<port>"
 export https_proxy="https://<hostname>:<port>"

在运行“python get-pip.py”之前

于 2017-03-14T06:36:15.130 回答
5
import requests
proxy = {
'http' : 'http://138.197.222.35:80',
'https' : 'http://1138.197.222.35:8080'
}

r = requests.get('http://httpbin.org/ip', proxies=proxy)
print (r)

在您的 ips 中附加“http://”和“https://”。
我在使用 linux 时遇到了这个问题,windows 单独使用 ip 可以正常工作。

于 2020-04-27T19:17:02.537 回答
5

利用pip install xxx --proxy=https://xx.xx.xx.xx:xxxx

Python 3.6以后,在使用proxy时,proxy的参数值发生了requests.get(url=url, headers=headers, proxies=...)变化。

3.6之前包含,proxies={ 'https': '127.0.0.1:8080'}还是proxies={'http': '127.0.0.1:8080'}可以的,但是这种类型的字典不适合Python 3.7及以上。

Python3.7及以上,必须在ip:port前面加上http://or https://,即,proxies={'http':'http://127.0.0.1:8080'}proxies={'https':'https://127.0.0.1:8080'}

于 2020-11-17T08:03:52.700 回答
0

对于您提到的问题,这取决于如何设置代理服务器身份验证。例如,我的 Intranet 使用 Windows AD,并且代理服务器可能正在使用 Windows Integrated auth。因此,当我这样做时pip install --proxy http://<server-ip>:<port> <module-name>,它工作正常。请注意,我不必输入用户名和密码,可能是由于集成的身份验证。

因此,您需要找出代理服务器正在使用的身份验证。您可以使用 Fiddler(或任何其他网络分析器)工具检查 407 响应中的 WWW-Authenticate 标头,以检查服务器支持的身份验证机制.

于 2017-05-05T15:44:54.590 回答
0

当您使用“;”时可能会出现这种情况 在您的密码中。这无法正确解析,导致引发 ProxySchemeUnknown 错误。

于 2018-04-19T11:27:20.293 回答
0

以下事情对我有用:

步骤 1) 设置 HTTPS_PROXY 和 HTTP_PROXY:

导出 HTTPS_PROXY="http://proxy-address:8080"

导出 HTTP_PROXY="http://proxy-address:8080"

步骤 2) : 使用以下配置运行 pip

./pip.exe install pyspark --trusted-host pypi.python.org --trusted-host files.pythonhosted.org --trusted-host pypi.org --proxy "proxy-address:8080"

于 2019-03-12T12:39:12.667 回答
0

在 Windows 上,您可以使用SET命令而不是export

  • SET HTTP_PROXY="http://proxy-address:8080"
  • SET HTTPS_PROXY="http://proxy-address:8080"

如果您不在代理后面,则需要像这样取消设置:

  • SET HTTP_PROXY=
  • SET HTTPS_PROXY=
于 2021-08-25T05:34:32.307 回答
0

它可以在win7上安装boto3。pip install boto3 --proxy=https://user:pwd@xxxx:8080

Collecting boto3
  Downloading boto3-1.20.33-py3-none-any.whl (131 kB)
Collecting botocore<1.24.0,>=1.23.33
  Downloading botocore-1.23.33-py3-none-any.whl (8.5 MB)
Collecting s3transfer<0.6.0,>=0.5.0
  Downloading s3transfer-0.5.0-py3-none-any.whl (79 kB)
Collecting jmespath<1.0.0,>=0.7.1
  Downloading jmespath-0.10.0-py2.py3-none-any.whl (24 kB)
Collecting python-dateutil<3.0.0,>=2.1
  Downloading python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB)
Collecting urllib3<1.27,>=1.25.4
  Downloading urllib3-1.26.8-py2.py3-none-any.whl (138 kB)
Collecting six>=1.5
  Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)
Installing collected packages: six, python-dateutil, jmespath, urllib3, botocore, s3transfer, boto3
Successfully installed boto3-1.20.33 botocore-1.23.33 jmespath-0.10.0 python-dateutil-2.8.2 s3transfer-0.5.0 six-1.16.0 urllib3-1.26.8
于 2022-01-12T06:22:06.653 回答