Add Zscaler CA root certificate to Python under Windows to solve the problem of Pip SSL access error

The company has deployed Zscaler, and all internet traffic is proxied through Zscaler to ensure data security. One problem is that the traffic of Python access is transferred to Zscaler, and the certificate error will be prompted.

  • The error message is as follows

pip install requests
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123)'))': /simple/requests/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123)'))': /simple/requests/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123)'))': /simple/requests/

  • The temporary solution is as follows. Add the --trusted-host parameter to pip so that the certificate verification can be ignored, but a warning will still be generated.

pip install requestes --trusted-host pypi.org --trusted-host files.pythonhosted.org
Collecting requestes
 Downloading requestes-0.0.1.tar.gz (1.4 kB)
Using legacy 'setup.py install' for requestes, since package 'wheel' is not installed.
Installing collected packages: requestes
   Running setup.py install for requestes ... done
Successfully installed requestes-0.0.1
WARNING: You are using pip version 20.2.3; however, version 21.0.1 is available.
You should consider upgrading via the 'c:\program files\python39\python.exe -m pip install --upgrade pip' command.

  • The solution once and for all is to add the root certificate of the proxy server to Python's Cert Store, the method is as follows

Python on Windows automatically includes PIP and Certifi, which are the default certificate bundles used for certificate verification.

Obtain the Zscaler Proxy CA root cert and import it into ""C:\Program Files\Python39\Lib\site-packages\pip\_vendor\certifi\cacert.pem"" to solve the problem.

Depending on the version of python installed, the path may be slightly different.

If you execute pip again to install third-party modules, no error will be reported.

image.png


Guess you like

Origin blog.51cto.com/sky2133/2676295