ERROR installing boto3 using pip on RHEL7 – Tunnel connection failed: 502 Bad Gateway

Question:

I am attempting to install boto3 on an ec2 instance running RHEL7.6. I am behind a proxy, and the proxy information is listed in /etc/environment. I am certain the proxy is working. I am able to curl the https://pypi.org and use our proxy regularly. I am running Python 2.7.5 and Pip 8.1.2.

I run the following command to produce the 502 Bad Gateway:
pip install --proxy http://<redacted-ip>:<redacted-port> -v --log pipinstall1.log boto3

I’ve included the –proxy flag because I encountered the same errors without it. I wanted to be sure that the proxy is used by pip, but to no avail.

I apologize for pasting the log directly, but I am unable to use hosting service to attach the log file.

Update

To eliminate the potential that Python 2.7.5 is too old to download from PyPi, I stood up a new ec2 instance running RHEL 8. This instance is running Python 3.6.8 and pip 9.0.3. I verified the proxy is working via curl https://pypi.org/simple/boto3/ and it returned successfully.

I am still receiving the 502 Bad Gateway when running:
pip3 --log pip3_log.txt --proxy http://<redacted-ip>:<redacted-port> --trusted-host pypi.org install boto3

The output of pip3_log.txt is below:

Answer:

I ran into the same issue a few days ago, because I was also using a proxy which had only 2 domains whitelisted: pypi.org and files.pythonhosted.org
The problem is that pip is running on an older version. In my case pip was running on version 9.0.1. This version of pip tries to look for packages at an old url pypi.python.org which now is actually redirected to pypi.org

You can upgrade pip offline by transferring the whl file. You can download it from here https://files.pythonhosted.org/packages/5a/4a/39400ff9b36e719bdf8f31c99fe1fa7842a42fa77432e584f707a5080063/pip-20.2.2-py2.py3-none-any.whl

Upgrade pip by running:

$ python3 -m pip install pip-20.2.2-py2.py3-none-any.whl

Verify pip is upgraded by running:

The newer pip looks for packages at pypi.org directly and downloads all files required from files.pythonhosted.org.
Once pip was upgraded, I was able to install pip packages.

Important note :

Please ensure you have whitelisted pypi.org and files.pythonhosted.org. Without access to these domains pip wont be able to install any package using internet.

Leave a Reply