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


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 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.


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 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 install boto3

The output of pip3_log.txt is below:


I ran into the same issue a few days ago, because I was also using a proxy which had only 2 domains whitelisted: and
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 which now is actually redirected to

You can upgrade pip offline by transferring the whl file. You can download it from here

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 directly and downloads all files required from
Once pip was upgraded, I was able to install pip packages.

Important note :

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

Leave a Reply