Python3.8 pip ProxyError:无法连接到 CentOS Linux 版本 7.9.2009 上的代理

Python3.8 pip ProxyError:无法连接到 CentOS Linux 版本 7.9.2009 上的代理

我在新安装的 CentOS 7 (7.9.2009) 服务器中使用 pip 安装库时遇到了问题。

我安装了 python 3.8.3,并立即将 pip 升级到最新版本 21.0.1。

已经导出我的 http_proxy 和 https_proxy 设置,

但是当我尝试通过 pip 安装库时出现此错误。

[root@localhost downloads]# pip3.8 install pandas --proxy https://user:[email protected]:808
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', timeout('_ssl.c:1091: The handshake operation timed out'))': /simple/pandas/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', timeout('_ssl.c:1091: The handshake operation timed out'))': /simple/pandas/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', timeout('_ssl.c:1091: The handshake operation timed out'))': /simple/pandas/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', timeout('_ssl.c:1091: The handshake operation timed out'))': /simple/pandas/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', timeout('_ssl.c:1091: The handshake operation timed out'))': /simple/pandas/
ERROR: Could not find a version that satisfies the requirement pandas
ERROR: No matching distribution found for pandas

我尝试使用详细模式来检查。

pip 代理错误

我尝试通过 curl 检查 pandas url 是否能访问它,结果是可以的。

[root@localhost downloads]# curl -I https://pypi.org/simple/pandas/
HTTP/1.1 200 Connection established
Proxy-agent: CCProxy

HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 381742
Cache-Control: max-age=600, public
Content-Security-Policy: default-src 'none'; sandbox allow-top-navigation
Content-Type: text/html; charset=UTF-8
ETag: "zPB5FsC5JkZZm1ZnKHnuUw"
Referrer-Policy: origin-when-cross-origin
Server: nginx/1.13.9
X-PyPI-Last-Serial: 9182431
Accept-Ranges: bytes
Date: Wed, 03 Feb 2021 07:44:51 GMT
X-Served-By: cache-bwi5146-BWI, cache-sin18034-SIN
X-Cache: HIT, HIT
X-Cache-Hits: 1, 1
X-Timer: S1612338291.161041,VS0,VE1
Vary: Accept-Encoding, Accept-Encoding
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
X-Frame-Options: deny
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
X-Permitted-Cross-Domain-Policies: none

我还尝试从所述存储库中获取最新的 pandas 文件,并且能够下载它。

[root@localhost downloads]# wget https://files.pythonhosted.org/packages/11/1c/b0bc154996617eae877ff267fcf84e55e6c6808dbade0da206f0419dd483/pandas-1.2.1.tar.gz#sha256=5527c5475d955c0bc9689c56865aaa2a7b13c504d6c44f0aadbf57b565af5ebd
--2021-02-03 10:47:24--  https://files.pythonhosted.org/packages/11/1c/b0bc154996617eae877ff267fcf84e55e6c6808dbade0da206f0419dd483/pandas-1.2.1.tar.gz
Connecting to 10.XXX.XXX.XXX:808... connected.
Proxy request sent, awaiting response... 200 OK
Length: 5459053 (5.2M) [application/x-tar]
Saving to: ‘pandas-1.2.1.tar.gz’

100%[============================================================================================>] 5,459,053    418KB/s   in 13s

2021-02-03 10:47:39 (399 KB/s) - ‘pandas-1.2.1.tar.gz’ saved [5459053/5459053]

我是不是漏掉了什么?我想是服务器设置导致了这个问题。还是只是代理不起作用?

答案1

  • 免责声明:以下是无耻的剽窃httpx 故障排除指南,但是人们需要帮助,就像这里,所以......

解决方案:您很可能已经像这样设置了代理......

proxies = {
  "http": "http://myproxy.org",
  "https": "https://myproxy.org",
}

使用此设置,您将尝试使用 HTTP 连接到代理以发送 HTTP 请求,并使用 HTTPS 连接到代理以发送 HTTPS 请求。

但如果您收到上述错误,则可能是您的代理不支持通过 HTTPS 连接。别担心:这是一个常见的问题。

将 HTTPS 代理的方案更改为 http://... 而不是 https://...:

proxies = {
  "http": "http://myproxy.org",
  "https": "http://myproxy.org",
}

这可以简化为:

proxies = "http://myproxy.org"

有关详细信息,请参阅For more information, see代理:FORWARD 与 TUNNEL

相关内容