gpt4 book ai didi

python - 如何让 PyC​​harm 在安装库时忽略 SSL 错误?

转载 作者:行者123 更新时间:2023-11-28 19:04:27 25 4
gpt4 key购买 nike

我正在尝试在使用自签名 SSL 证书的公司网络上将 requests 库安装到我在 PyCharm 中的 Python 环境中。因此,使用 File > Settings > Project > Project Interpreter > Install 安装库失败并出现 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

我还尝试打开 File > Settings > Project > Server Certificates 并选中Accept non-trusted certificates automatically,但遇到了同样的问题。

如何让 PyC​​harm 在安装外部库时忽略 SSL 证书错误?

最佳答案

我遇到了同样的问题。我解决它的方法是将我想要安装的所有包添加到 .txt 文件中,例如requirements.txt 包含所有包名称及其版本。

然后从终端(也可以是 PyCharm 终端),我做了:

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

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

关于python - 如何让 PyC​​harm 在安装库时忽略 SSL 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48627632/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com