我正在尝试创建一个虚拟环境,我过去可以通过诗歌安装来做到这一点。但现在,当尝试执行
poetry install
时,我收到此消息:
Max retries exceeded with url: /pypi/six/1.16.0/json (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)')))
at ~/.poetry/lib/poetry/_vendor/py3.9/requests/adapters.py:514 in send
510│ raise ProxyError(e, request=request)
511│
512│ if isinstance(e.reason, _SSLError):
513│ # This branch is for urllib3 v1.22 and later.
→ 514│ raise SSLError(e, request=request)
515│
516│ raise ConnectionError(e, request=request)
517│
518│ except ClosedPoolError as e:
什么对我有用(MacOS) 转到应用程序 > Python 文件夹 > 双击“Install Certificates.command”文件
Python 的 requests 库似乎找不到您的证书。
您是否使用自签名证书配置了自定义存储库? 如果是这样,我还没有找到解决这个问题的伟大的解决方案。 在这种情况下,请检查您是否设置了 CURL_CA_BUNDLE 环境变量:
$ 回显$CURL_CA_BUNDLE
如果这指向某个自定义位置/自签名证书,请求将无法使用其标准证书包。 您可以取消设置(可能会对使用它的服务产生副作用):
导出 CURL_CA_BUNDLE=""
如果您尚未配置任何自定义存储库/证书:
您也许可以通过安装 certifi
来解决此问题Python 3.7 安装在 MacOSX 系统上时需要运行一个脚本,通过 bash 在您的系统上为 python 环境安装证书依赖项。
#!/bin/sh
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7 << "EOF"
# install_certifi.py
#
# sample script to install or update a set of default Root Certificates
# for the ssl module. Uses the certificates provided by the certifi package:
# https://pypi.org/project/certifi/
import os
import os.path
import ssl
import stat
import subprocess
import sys
STAT_0o775 = ( stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR
| stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP
| stat.S_IROTH | stat.S_IXOTH )
def main():
openssl_dir, openssl_cafile = os.path.split(
ssl.get_default_verify_paths().openssl_cafile)
print(" -- pip install --upgrade certifi")
subprocess.check_call([sys.executable,
"-E", "-s", "-m", "pip", "install", "--upgrade", "certifi"])
import certifi
# change working directory to the default SSL directory
os.chdir(openssl_dir)
relpath_to_certifi_cafile = os.path.relpath(certifi.where())
print(" -- removing any existing file or link")
try:
os.remove(openssl_cafile)
except FileNotFoundError:
pass
print(" -- creating symlink to certifi certificate bundle")
os.symlink(relpath_to_certifi_cafile, openssl_cafile)
print(" -- setting permissions")
os.chmod(openssl_cafile, STAT_0o775)
print(" -- update complete")
if __name__ == '__main__':
main()
EOF
这是安装 certifi 包 ssl 证书的 bash 脚本的内容。它还应该位于应用程序中安装的 Python 文件夹中。
cd /Applications/Python\ 3.7/
./Install\ Certificates.command
要完成有关MacOs的答案,如果通过brew安装Python,您将找不到可执行文件
Install Certificates.command
。
但是你可以通过brew安装certifi来解决这个问题,通过:
brew install certifi