urllib.error.URLError:<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED]

问题描述 投票:0回答:2

我安装了seaborn Python 包并尝试运行第一个教程,它生成了一系列错误。

我做错了什么?我将教程代码复制并粘贴到名为 seaborn1.py 的文件中,然后单击“运行”,我得到了以下结果:

/Users/apple/python/python-venv/bin/python3.12 /Users/apple/python/project1/seaborn1.py 
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/urllib/request.py", line 1344, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/http/client.py", line 1319, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/http/client.py", line 1365, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/http/client.py", line 1314, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/http/client.py", line 1074, in _send_output
    self.send(msg)
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/http/client.py", line 1018, in send
    self.connect()
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/http/client.py", line 1460, in connect
    self.sock = self._context.wrap_socket(self.sock,
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/ssl.py", line 455, in wrap_socket
    return self.sslsocket_class._create(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/ssl.py", line 1046, in _create
    self.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/ssl.py", line 1317, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/apple/python/project1/seaborn1.py", line 8, in <module>
    tips = sns.load_dataset("tips")
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/apple/python/python-venv/lib/python3.12/site-packages/seaborn/utils.py", line 595, in load_dataset
    if name not in get_dataset_names():
                   ^^^^^^^^^^^^^^^^^^^
  File "/Users/apple/python/python-venv/lib/python3.12/site-packages/seaborn/utils.py", line 522, in get_dataset_names
    with urlopen(DATASET_NAMES_URL) as resp:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/urllib/request.py", line 215, in urlopen
    return opener.open(url, data, timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 ...
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/urllib/request.py", line 492, in _call_chain
    result = func(*args)
             ^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/urllib/request.py", line 1392, in https_open
    return self.do_open(http.client.HTTPSConnection, req,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/urllib/request.py", line 1347, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)>

Process finished with exit code 1
python python-3.x ssl-certificate seaborn
2个回答
2
投票

您可以转到聚光灯(搜索栏)并搜索

"Install Certificates.command"
然后按 Enter。

或者

Macintosh HD-> Applications-> Python3.12 -> double click "Install Certificates.command"
文件


1
投票

tl;dr:您的网络堆栈安装缺少必要的根证书。

您致电

sns.load_dataset("tips")
尝试访问 https://github.com/mwaskom/seaborn-data 下的 CSV,特别是 https://raw.githubusercontent.com/mwaskom/seaborn-data/master/tips.csv

如果没有 DigiCert TLS RSA SHA256 2020 CA1 证书,一切都不会顺利。


如果您使用venv、conda或poetry来获取cPython+库, 这一切都会非常顺利,无需你多想。

© www.soinside.com 2019 - 2024. All rights reserved.