tl;dr

use python -m pip --trusted-host <hostname>

$ python -m pip install \ 
  --trusted-host pypi.org \
  --trusted-host files.pythonhosted.org \
  -r requirements.txt

Errors of pip and upgrading

# SSL error
$ pip install -r requirements.txt

  Could not fetch URL https://pypi.org/simple/selenium/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/selenium/ (Caused by SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:726)'),)) - skipping
  Could not find a version that satisfies the requirement selenium (from versions: )
No matching distribution found for selenium
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:726)'),)) - skipping


# tried upgrading but still SSL error
$ pip install --upgrade pip

Could not fetch URL https://pypi.python.org/simple/pip/: There was a problem confirming the ssl certificate: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749) - skipping


# tried upgrading by curl and get-pip.py
$ curl https://bootstrap.pypa.io/get-pip.py | python

curl: (60) Peer's certificate issuer has been marked as not trusted by the user.
More details here: https://curl.haxx.se/docs/sslcerts.html

curl performs SSL certificate verification by default, using a "bundle"
 of Certificate Authority (CA) public keys (CA certs). If the default
 bundle file isn't adequate, you can specify an alternate file
 using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
 the bundle, the certificate verification probably failed due to a
 problem with the certificate (it might be expired, or the name might
 not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
 the -k (or --insecure) option.


#upgraded but still SSL error...
$ curl -k -o /tmp/get-pip.py https://bootstrap.pypa.io/get-pip.py && \
  python /tmp/get-pip.py --trusted-host pypi.org --trusted-host files.pythonhosted.org && \
$ pip install -r requirements.txt

Collecting selenium (from -r requirements.txt (line 1))
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)'),)': /simple/selenium/
  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)'),)': /simple/selenium/
  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)'),)': /simple/selenium/
  Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)'),)': /simple/selenium/
  Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)'),)': /simple/selenium/
  Could not fetch URL https://pypi.org/simple/selenium/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/selenium/ (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)'),)) - skipping
  Could not find a version that satisfies the requirement selenium (from -r requirements.txt (line 1)) (from versions: )
No matching distribution found for selenium (from -r requirements.txt (line 1))

Successed with -m and --trusted-host options

$ python -m pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org -r requirements.txt

Installing collected packages: urllib3, selenium
Successfully installed selenium-3.14.1 urllib3-1.23

So, my Dockerfile for serverless Python is below now

FROM lambci/lambda:build-python3.6

Add requirements.txt .

RUN python -m pip install \
  --trusted-host pypi.org \
  --trusted-host files.pythonhosted.org \
  -r requirements.txt

Leave a Reply

Your email address will not be published. Required fields are marked *