首页 文章

python ssl wrap_socket connect faied到一个安全的websocket服务

提问于
浏览
0
context = ssl.create_default_context()
conn = context.wrap_socket(socket.socket(socket.AF_INET,socket.SOCK_STREAM),server_hostname=hostname)
conn.connect((hostname,443))

我只想从安全的websocket服务获取证书信息 . 它返回此错误消息:

[SSL:CERTIFICATE_VERIFY_FAILED]证书验证失败(_ssl.c:590)

这段代码出了什么问题?

1 回答

  • 0

    我找到了解决它的新解决方案

    certfile="/tmp/cert.pem" #your CA chain
    context.verify_mode=ssl.CERT_REQUIRED
    context.check_hostname = True
    context.load_verify_locations(certfile)
    

相关问题