Mac(由 SSLError(SSLCertVerificationError

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

我正在尝试使用 Macbook 中的 Python 库之一连接到 NSE 站点。它抛出 SSL 错误。

import ssl
ssl._create_default_https_context = ssl._create_stdlib_context
from datetime import date
from nsepy import get_history
sbin = get_history(symbol='SBIN',start=date(2024,4,1),
                   end=date(2024,4,4))

完全错误

Traceback (most recent call last):
  File "/Users//PycharmProjects/pythonProject/pythonProject/.venv/lib/python3.12/site-packages/urllib3/util/ssl_.py", line 509, in _ssl_wrap_socket_impl
    return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  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//PycharmProjects/pythonProject/pythonProject/.venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 793, in urlopen
    response = self._make_request(
               ^^^^^^^^^^^^^^^^^^^
  File "/Users//PycharmProjects/pythonProject/pythonProject/.venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 491, in _make_request
    raise new_e
urllib3.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users//PycharmProjects/pythonProject/pythonProject/.venv/lib/python3.12/site-packages/requests/adapters.py", line 486, in send
    resp = conn.urlopen(
           ^^^^^^^^^^^^^
  File "/Users//PycharmProjects/pythonProject/pythonProject/.venv/lib/python3.12/site-packages/urllib3/connectionpool.py", line 847, in urlopen
    retries = retries.increment(
              ^^^^^^^^^^^^^^^^^^
  File "/Users//PycharmProjects/pythonProject/pythonProject/.venv/lib/python3.12/site-packages/urllib3/util/retry.py", line 515, in increment
    raise MaxRetryError(_pool, url, reason) from reason  # type: ignore[arg-type]
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='www1.nseindia.com', port=443): Max retries exceeded with url: /products/dynaContent/common/productsSymbolMapping.jsp?dataType=PRICEVOLUMEDELIVERABLE&segmentLink=3&dateRange=&symbol=SBIN&series=EQ&symbolCount=1&fromDate=01-04-2024&toDate=04-04-2024 (Caused by SSLError(SSLCertVerificationError(1, '[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//PycharmProjects/pythonProject/pythonProject/.venv/lib/python3.12/site-packages/requests/sessions.py", line 266, in resolve_redirects
    resp = self.send(
           ^^^^^^^^^^
  File "/Users//PycharmProjects/pythonProject/pythonProject/.venv/lib/python3.12/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users//PycharmProjects/pythonProject/pythonProject/.venv/lib/python3.12/site-packages/requests/

adapters.py", line 517, in send
        raise SSLError(e, request=request)
    requests.exceptions.SSLError: HTTPSConnectionPool(host='www1.nseindia.com', port=443): Max retries exceeded with url: /products/dynaContent/common/productsSymbolMapping.jsp?
dataType=PRICEVOLUMEDELIVERABLE&segmentLink=3&dateRange=&symbol=SBIN&series=EQ&symbolCount=1&fromDate=01-04-2024&toDate=04-04-2024 (Caused by SSLError(SSLCertVerificationError
(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)')))

我确实尝试过。安装

Installing Certificate.command

Update Shell Profile. command.

已添加

import ssl
ssl._create_default_https_context = ssl._create_stdlib_context

在钥匙串访问中添加了 nse 证书。

尝试升级证书。

pip install --upgrade certifi

但是没有成功。你能帮我解决这个问题吗?

谢谢

python macos python-ssl
1个回答
0
投票

Mac 防火墙问题。向 Mac 服务中心人员寻求帮助,并能够向防火墙添加例外。

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