python连接wws协议和http协议时ssl验证失败

用python连接wss代码如下:

from websocket import create_connection
url = "wss://api.com"
ws = create_connection(url)

报错,ssl验证失败

ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:719)

解决方法:
wss下跳过ssl验证

import ssl
ws = create_connection(self.url, sslopt={"cert_reqs": ssl.CERT_NONE})
# 另一种写法
ws.run_forever(sslopt={"cert_reqs": ssl.CERT_NONE})

http下解决方法:

import ssl
ssl._create_default_https_context = ssl._create_unverified_context

你可能感兴趣的:(python)