Python 在带有 CNTLM 的代理后面使用 pip

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14149422/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 10:36:43  来源:igfitidea点击:

Using pip behind a proxy with CNTLM

pythonproxypip

提问by Rob

I am trying to use pip behind a proxy at work.

我正在尝试在工作中使用代理背后的 pip。

One of the answers from this postsuggested using CNTLM. I installed and configured it per this other post, but running cntlm.exe -c cntlm.ini -I -M http://google.comgave the error Connection to proxy failed, bailing out.

这篇文章中的一个答案建议使用CNTLM。我按照其他帖子安装并配置了它,但运行时cntlm.exe -c cntlm.ini -I -M http://google.com出现错误Connection to proxy failed, bailing out

I also tried pip install -–proxy=user:pass@localhost:3128(the default CNTLM port) but that raised Cannot fetch index base URL http://pypi.python.org/simple/. Clearly something's up with the proxy.

我也尝试过pip install -–proxy=user:pass@localhost:3128(默认的 CNTLM 端口),但引发了Cannot fetch index base URL http://pypi.python.org/simple/. 很明显,代理出了点问题。

Does anyone know how to check more definitively whether CNTLM is set up right, or if there's another way around this altogether? I know you can also set the http_proxyenvironment variable as described herebut I'm not sure what credentials to put in. The ones from cntlm.ini?

有谁知道如何更明确地检查 CNTLM 是否设置正确,或者是否还有其他方法可以解决这个问题?我知道您也可以http_proxy按照此处所述设置环境变量,但我不确定要放入哪些凭据。来自cntlm.ini?

采纳答案by Annie Lagang

To setup CNTLM for windows, follow this article. For Ubuntu, read my blog post.

要为 Windows 设置 CNTLM,请按照这篇文章。对于 Ubuntu,请阅读我的博客文章

Edit:

编辑:

Basically, to use CNTLM in any platform, you need to setup your username and hashedpassword, before using http://127.0.0.1:3128as a proxy to your parent proxy.

基本上,要在任何平台上使用 CNTLM ,在用作父代理的代理之前,您需要设置您的用户名和散列密码http://127.0.0.1:3128

  1. Edit the config and add important information like domain, username, password and parent proxy.

  2. Generate hashed password.

    Windowscntlm –c cntlm.ini –H

    Ubuntu/Linuxcntlm -v -H -c /etc/cntlm.conf

  3. Remove plain text password from the config and replace them with the generated passwords.

  1. 编辑配置并添加重要信息,如域、用户名、密码和父代理。

  2. 生成散列密码。

    视窗cntlm –c cntlm.ini –H

    Ubuntu/Linuxcntlm -v -H -c /etc/cntlm.conf

  3. 从配置中删除纯文本密码并将其替换为生成的密码。

To check if working:

要检查是否工作:

Windowscntlm –M http://www.google.com

视窗cntlm –M http://www.google.com

Ubuntu/Linuxsudo cntlm -M http://www.google.com/

Ubuntu/Linuxsudo cntlm -M http://www.google.com/

For more detailed instructions, see links above.

有关更详细的说明,请参阅上面的链接。

Update:

更新:

Just for completeness sake, I was able to configure and use CNTLM in Windows recently. I encountered a problem during the syncing process of Kindle for PC because of our proxy and installing and configuring CNTLM for Windows fixed that issue for me. Refer to my articlefor more details.

为了完整起见,我最近能够在 Windows 中配置和使用 CNTLM。我在 PC 版 Kindle 同步过程中遇到了一个问题,因为我们的代理和安装和配置 CNTLM for Windows 为我解决了这个问题。详情请参阅我的文章

回答by namit

for windows; set your proxy in command prompt as
set HTTP_PROXY=domain\username:password@myproxy:myproxyport

用于窗户;在命令提示符中将您的代理设置为
set HTTP_PROXY=domain\username:password@myproxy:myproxyport

example:
set http_proxy=IND\namit.kewat:[email protected]:8880

例子:
set http_proxy=IND\namit.kewat:[email protected]:8880

回答by Johan Chouquet

I had the same issue : behind a corporate proxy with auth at work, I couldn't have pip work, as well as Sublime Text 2 (well, it worked with custom setup of my proxy settings). For pip (and I'll try that on git), I solved it installing cntlm proxy. It was very simple to configure :

我遇到了同样的问题:在带有 auth 工作的公司代理后面,我无法使用 pip 以及 Sublime Text 2(好吧,它与我的代理设置的自定义设置一起使用)。对于 pip(我会在 git 上尝试),我通过安装 cntlm 代理解决了这个问题。配置非常简单:

  1. Edit cntlm.ini
  2. Edit "Username", "Domain", "Password" fields
  3. Add a "Proxy" line, with your proxy settings : server:port
  4. Make sure the line "NoProxy" integrates "localhost" (like that by default)
  5. Note the default port : 3128
  6. Save and that's it.
  1. 编辑 cntlm.ini
  2. 编辑“用户名”、“域”、“密码”字段
  3. 添加“代理”行,使用您的代理设置: server:port
  4. 确保“NoProxy”行集成了“localhost”(默认情况下是这样)
  5. 注意默认端口:3128
  6. 保存,就是这样。

To test that works, just launch a new command line tool, and try :

要测试它是否有效,只需启动一个新的命令行工具,然后尝试:

pip install django --proxy=localhost:3128

That worked for me. Hope this will help you.

那对我有用。希望这会帮助你。

回答by k7sleeper

Under Windows dont forget to set

在 Windows 下不要忘记设置

SET HTTPS_PROXY=<proxyHost>:<proxyPort>

what I needed to set for

我需要设置什么

pip install pep8

回答by bbaassssiiee

Under our security policy I may not use httpswith pypi, SSL-inspection rewrites certificates, it breaks the built-in security of pip for www.python.org. The man in the middle is the network-admin.

根据我们的安全政策,我可能不会将 https与 pypi 一起使用,SSL 检查会重写证书,它破坏了 www.python.org 的 pip 的内置安全性。中间的人是网络管理员。

So I need to use plain http. To do so I need to override the system proxy as well as the default pypi:

所以我需要使用普通的 http。为此,我需要覆盖系统代理以及默认的 pypi:

bin/pip install --proxy=squidproxy:3128 -i http://www.python.org/pypi --upgrade "SQLAlchemy>=0.7.10"

回答by Sameer Vaidya

With Ubuntu I could not get the proxy option to work as advertised – so following command did notwork:

与Ubuntu我不能让代理选项,以工作为标榜-所以下面的命令做了工作:

sudo pip --proxy http://web-proxy.mydomain.com install somepackage

But exporting the https_proxyenvironment variable (note its https_proxynot http_proxy) did the trick:

但是导出https_proxy环境变量(注意https_proxy不是http_proxy)可以解决问题:

export https_proxy=http://web-proxy.mydomain.com

then

然后

sudo -E pip install somepackage

回答by Tommy O'Dell

Phone as mobile hotspot/USB tethering

手机作为移动热点/USB 网络共享

If I have much trouble finding a way through the corporate proxy, I connect to the web through my phone (wireless hotspot if I have wifi, USB tether if not) and do a quick pip install.

如果我很难通过公司代理找到方法,我会通过手机连接到网络(如果我有 wifi,则为无线热点,如果没有,则使用 USB 系绳)并快速执行pip install.

Might not work for all setups, but should get most people by in a pinch.

可能不适用于所有设置,但应该让大多数人在紧要关头。

回答by djmoch

You can continue to use pip over HTTPS by adding your corporation's root certificate to the cacert.pem file in your site-packages/pip folder. Then configure pip to use your proxy by adding the following lines to ~/pip/pip.conf (or ~\pip\pip.ini if you're on Windows):

您可以通过将您公司的根证书添加到您的 site-packages/pip 文件夹中的 cacert.pem 文件来继续通过 HTTPS 使用 pip。然后通过将以下几行添加到 ~/pip/pip.conf (或 ~\pip\pip.ini 如果您使用的是 Windows)来配置 pip 以使用您的代理:

[global]
proxy = [user:passwd@]proxy.server:port

That's it. No need to use third party packages or give up HTTPS (of course, your network admin can still see what you're doing).

就是这样。无需使用第三方软件包或放弃 HTTPS(当然,您的网络管理员仍然可以看到您在做什么)。

回答by Sendi_t

How about just doing it locally? Most likely you are able to download from https source through your browser

只在本地做怎么样?您很可能可以通过浏览器从 https 源下载

  1. Download your module file (mysql-connector-python-2.0.3.zip /gz... etc).
  2. Extract it and go the extracted dir where setup.py is located and call:

    C:\mysql-connector-python-2.0.3>python.exe setup.py install
    
  1. 下载您的模块文件(mysql-connector-python-2.0.3.zip /gz...等)。
  2. 提取它并转到 setup.py 所在的提取目录并调用:

    C:\mysql-connector-python-2.0.3>python.exe setup.py install
    

回答by Nitin Panwar

For windows users: if you want to install Flask-MongoAlchemy then use the following code

对于 windows 用户:如果你想安装 Flask-MongoAlchemy 则使用以下代码

pip install Flask-MongoAlchemy --proxy="http://example.com:port"**