Pip + virtualenv + Redhat SCL + 代理 = 不起作用

Pip + virtualenv + Redhat SCL + 代理 = 不起作用

我正在 Redhat Enterprise 6(默认情况下附带 2.6.x)中基于 Python 2.7 设置虚拟环境。

我安装了 SCL 2.7 版本的 Python,然后创建了虚拟环境:

$ scl enable python27 bash
$ cd /my/project
$ virtualenv -v --clear --extra-search-dir=/opt/rh/python27/root/usr/bin/ --python=/opt/rh/python27/root/usr/bin/python virtualenv
$ source virtualenv/bin/acticvate

到目前为止一切顺利。当我尝试在我所在机构的代理后面运行 pip 时,问题就开始了:

$ pip install Werkzeug --proxy proxy.example.org:3128                       
Downloading/unpacking Werkzeug                                                 
Cleaning up...                                                                 
Exception:                                                                     
Traceback (most recent call last):                                             
  File "/my/project/virtualenv/lib/python2.7/site-packages/pip/basecommand.py", line 134, in main
    status = self.run(options, args)                                           
  File "/my/project/virtualenv/lib/python2.7/site-packages/pip/commands/install.py", line 236, in run
    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
  File "/my/project/virtualenv/lib/python2.7/site-packages/pip/req.py", line 1085, in prepare_files
    url = finder.find_requirement(req_to_install, upgrade=self.upgrade)        
  File "/my/project/virtualenv/lib/python2.7/site-packages/pip/index.py", line 201, in find_requirement
    page = self._get_page(main_index_url, req)                                 
  File "/my/project/virtualenv/lib/python2.7/site-packages/pip/index.py", line 554, in _get_page
    return HTMLPage.get_page(link, req, cache=self.cache)                      
  File "/my/project/virtualenv/lib/python2.7/site-packages/pip/index.py", line 671, in get_page
    resp = urlopen(url)                                                        
  File "/my/project/virtualenv/lib/python2.7/site-packages/pip/download.py", line 176, in __call__
    response = self.get_opener(scheme=scheme).open(url)                        
  File "/opt/rh/python27/root/usr/lib64/python2.7/urllib2.py", line 404, in open
    response = self._open(req, data)                                           
  File "/opt/rh/python27/root/usr/lib64/python2.7/urllib2.py", line 422, in _open
    '_open', req)                                                              
  File "/opt/rh/python27/root/usr/lib64/python2.7/urllib2.py", line 382, in _call_chain
    result = func(*args)                                                       
  File "/my/project/virtualenv/lib/python2.7/site-packages/pip/download.py", line 155, in https_open
    return self.do_open(self.specialized_conn_class, req)                      
  File "/opt/rh/python27/root/usr/lib64/python2.7/urllib2.py", line 1183, in do_open
    h.request(req.get_method(), req.get_selector(), req.data, headers)         
  File "/opt/rh/python27/root/usr/lib64/python2.7/httplib.py", line 1001, in request
    self._send_request(method, url, body, headers)                             
  File "/opt/rh/python27/root/usr/lib64/python2.7/httplib.py", line 1035, in _send_request
    self.endheaders(body)                                                      
  File "/opt/rh/python27/root/usr/lib64/python2.7/httplib.py", line 997, in endheaders
    self._send_output(message_body)                                            
  File "/opt/rh/python27/root/usr/lib64/python2.7/httplib.py", line 850, in _send_output
    self.send(msg)                                                             
  File "/opt/rh/python27/root/usr/lib64/python2.7/httplib.py", line 812, in send
    self.connect()                                                             
  File "/my/project/virtualenv/lib/python2.7/site-packages/pip/download.py", line 139, in connect
    match_hostname(self.sock.getpeercert(), self.host)                         
  File "/my/project/virtualenv/lib/python2.7/site-packages/pip/backwardcompat/ssl_match_hostname.py", line 61, in match_hostname
    % (hostname, ', '.join(map(repr, dnsnames))))                              
CertificateError: hostname 'proxy.example.org' doesn't match either of 'www.python.org', 'python.org', 'pypi.python.org', 'docs.python.org', 'testpypi.python.org', 'bug>>>s.python.org', 'wiki.python.org', 'hg.python.org', 'mail.python.org', 'packaging.python.org', 'pythonhosted.org', 'www.pythonhosted.org', 'test.pythonhosted.org', 'us.py>>>con.org', 'id.python.org', 'pypi.io'

我在其他问题中看到过这个问题,但这些似乎都不适用于我的情况。

编辑:

例如我尝试设置环境变量https://stackoverflow.com/questions/21468550/pip-not-working-behind-firewall. 其他案例正在解决 Windows 问题。

值得一提的是,如果我不在 scl 环境中,这个虚拟环境将无法工作,例如,如果我调用python启用虚拟环境但不启用 scl,它会抱怨找不到 libpython2.7.so.1.0。我不知道这是否是 bny 设计,但我希望 Python 2.7 所依赖的所有库都符号链接或复制到虚拟环境中。也许我在虚拟环境安装中做错了什么?

答案1

您现在可能已经解决了这个问题,但似乎需要使用受信任的主机选项:

pip install Werkzeug --proxy proxy.example.org:3128 --trusted-host proxy.example.org

相关内容