证书验证失败:无法获取本地发行者证书(_ssl.c:1051)Python

时间:2020-04-19 08:50:40

标签: python-3.x ssl

我正在尝试连接到Websocket,即使我更新了证书,仍然无法连接到Websocket:

python3 -m pip install --upgrade --user  certifi
Requirement already up-to-date: certifi in /Users/t**/Library/Python/3.7/lib/python/site-packages (2020.4.5.1)

这是代码:

import asyncio
import logging
import websockets
from websockets import WebSocketClientProtocol

logging.basicConfig(level=logging.INFO)


async def consumer_handler(websocket: WebSocketClientProtocol) -> None:
    async for message in websocket:
        log_message(message)


async def consume(hostname: str) -> None:
    websocket_resource_url = f'wss://{hostname}'
    async with websockets.connect(websocket_resource_url) as websocket:
        await consumer_handler(websocket)


def log_message(message: str) -> None:
    logging.info(f'Message: {message}')


if __name__ == '__main__':
    asyncio.run(consume(hostname='echo.websocket.org'))

那是回报的最后一部分:

  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 763, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1051)

知道为什么吗?

0 个答案:

没有答案