如何在安装库时让PyCharm忽略SSL错误?

3

我正在尝试在使用自签名SSL证书的公司网络上,在PyCharm中将requests库安装到我的Python环境中。结果,使用文件>设置>项目>项目解释器>安装安装库时出现HTTPS错误:

Collecting requests
  Retrying (Retry(total=0, connect=None, read=None, redirect=None)) after connection
    broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.
    VerifiedHTTPSConnection object at 0x0368D5D0>: Failed to establish a new connection:
    [Errno 11003] getaddrinfo failed',)': /simple/requests/
  Could not find a version that satisfies the requirement requests (from versions: )
No matching distribution found for requests

我尝试使用以下选项 --cert C:\COMPANY-CAROOT.pem,使pip信任我们公司的根证书进行安装,但实际上是这样解释的:

pip install --cert C:\COMPANY-CAROOT.pem requests

我也尝试过打开文件 > 设置 > 项目 > 服务器证书并勾选自动接受非信任证书,但遇到了相同的问题。
当安装外部库时,如何让PyCharm忽略SSL证书错误?
1个回答

1
我遇到了同样的问题。我解决它的方法是在一个 .txt 文件中添加我想要安装的所有包,例如 requirements.txt,其中包含所有包名称及其版本。
然后从终端(也可以是 PyCharm 终端)执行以下操作:
pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org -r requirements.txt

关键在于使用 --trusted-host。将包添加到文件中只是为了方便。 或者,您可以创建一个 pip.ini 文件并在其中添加可信主机。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接