python - Python SSL 套接字错误 ssl.SSLCertVerificationError
问题描述
我正在测试 Python SSL 文档中的示例,
然后我尝试使用我自己的证书,它会弹出这个:
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)
我知道这个错误正在发生,因为我使用的是自签名证书,
但我不会花很多钱,因为它需要改变。
我想跳过验证,所以它将使用证书作为加密。
我怎样才能使用该代码做到这一点:
客户:
import socket
import ssl
hostname = 'localhost'
context = ssl.create_default_context()
with socket.create_connection((hostname, 443)) as sock:
with context.wrap_socket(sock, server_hostname=hostname) as ssock:
print(ssock.version())
服务器:
context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
context.load_cert_chain('certs/setver.crt', 'certs/private.key')
with socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0) as sock:
sock.bind(('127.0.0.1', 8443))
sock.listen(5)
with context.wrap_socket(sock, server_side=True) as ssock:
conn, addr = ssock.accept()
# Rest of the code...
解决方案
推荐阅读
- python - Keras 模型产生恒定的零输出
- jquery - 如何用新值刷新 dropdown-menu.inner li
- html - 屏幕调整大小时将元素贴近段落的单词
- c# - 如何检查xml值的条件?
- json - Newtonsoft JSON - 如何反序列化自定义集合?
- javascript - 在javascript中跳过假期时显示下一个日期
- apache-dolphinscheduler - dev 分支删除了 install.sh 脚本?
- sql - 如何从两列中提取数据,因为我缺少 regexp_match(..) 之类的函数
- selenium - 在 testng.xml 中运行为 testng 套装触发 IE 浏览器并手动运行每个测试,它使用 chrome 运行。为什么这样?
- django - 如何只允许Django UpdateView中文章的作者访问文章更新页面?