Centos – Python3.8 pip ProxyError: Cannot connect to proxy on CentOS Linux release 7.9.2009

centoscentos7pippython

Im having trouble installing libraries using pip in my freshly installed CentOS 7 (7.9.2009) server.

I installed python 3.8.3 and upgrade the pip right away to the latest version 21.0.1.

Already exported my http_proxy and https_proxy settings,

But when I try to install libraries via pip I get this error.

[root@localhost downloads]# pip3.8 install pandas --proxy https://user:pwd@10.XXX.XXX.XXX: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

I tried the verbose mode to check.

pip proxy error

I tried to check tha pandas url via curl if i can access it, and yes I can.

[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

I also tried to wget the latest pandas file in the said repository and I was able to download it.

[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]

Am I missing something here? Im thinking of server setting that is causing this. Or is it just the proxy is not working?

Best Answer

Resolution: it is likely that you've set up your proxies like this...

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

Using this setup, you're trying to connect to the proxy using HTTP for HTTP requests, and using HTTPS for HTTPS requests.

But if you get the error above, it is likely that your proxy doesn't support connecting via HTTPS. Don't worry: that's a common gotcha.

Change the scheme of your HTTPS proxy to http://... instead of https://...:

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

This can be simplified to:

proxies = "http://myproxy.org"

For more information, see Proxies: FORWARD vs TUNNEL.

Related Topic