在公司代理后面使用 Anaconda#
在公司代理后面使用 Anaconda 的存储库时,由于您的 IT 部门管理的自定义安全配置文件,您可能会遇到如下所示的 HTTP 和 SSL 错误。
CondaHTTPError: HTTP 000 CONNECTION FAILED for url https://repo.anaconda.com/pkgs/main/win-64/current_repodata.jsonElapsed:
An HTTP error occurred when trying to retrieve this URL.
HTTP errors are often intermittent, and a simple retry will get you on your way.
If your current network has https://www.anaconda.com blocked, please file
a support request with your network engineering team.
ConnectTimeout(MaxRetryError("HTTPSConnectionPool(host='repo.anaconda.com', port=443):
Max retries exceeded with url: /pkgs/main/win-64/current_repodata.json
(Caused by ConnectTimeoutError(<urllib3.connection.VerifiedHTTPSConnection object
at 0x000001B79FFE3278>, 'Connection to repo.anaconda.com timed out.
(connect timeout=9.15)'))"))
有三种可能的方法可以解决此问题。首先更新.condarc
file 中,然后再尝试其他方法。
更新 .condarc 文件#
Anaconda 建议更新您的.condarc
文件以包含proxy_servers
钥匙。这是首选方法,因为它只会影响 conda,而不会影响系统环境变量。
阅读有关 .condarc 文件和使用代理的更多信息。
例如:
proxy_servers:
http: http://username:password@corp.com:8080
https: https://username:password@corp.com:8080
您可以通过运行conda info --all
.
更新环境变量#
您还可以通过更新系统环境变量来解决此错误。这可能会影响整个系统中的所有 CLI 软件。
要在 Windows 上更改环境变量:
在 Start (开始) 菜单中,搜索 “env”。
选择 “Edit Environment Variables for your account”(编辑您账户的环境变量)。
选择 “Environment Variables...”。
按“新建...”。
添加两个变量
http_proxy
和https_proxy
两者具有相同的值:http://proxy-XX:XXX
要在 macOS 上更改环境变量:
通过运行
printenv
在终端中。要检查特定的环境变量,请使用
echo $variable_name
.通过运行
export variable_name=variable_value
.您可以通过运行conda info --all
.
要永久更改 macOS 上的环境变量,请查看本指南。
要在 Linux 上更改环境变量:
跑
export variable_name=variable_value
.要从 shell 输出环境变量的值,请运行
echo $variable_name
.
阅读有关取消设置、列出和保留环境变量的更多信息。
用.netrc
认证#
一个.netrc
file 是实现设置*_PROXY
环境变量或仅为 conda 配置内容.condarc
文件。此方法的风险在于,更改此处的环境变量将影响整个系统设置。
阅读有关 .netrc 文件的更多信息。