使用Python请求信任自签名证书

2024-05-13 10:01:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我的apache ssl conf有以下配置

#   Server Certificate:
SSLCertificateFile /etc/pki/tls/certs/localhost.crt

#   Server Private Key:
SSLCertificateKeyFile /etc/pki/tls/private/localhost.key

我没有此服务器的CA证书。我是否仍可以将localhost.crt安装到我的客户端以成功验证我的服务器?

在客户机上: 我正在使用Python请求库(2.2.1)。使用默认的CA束路径。即使我在默认路径中将localhost.crt添加到cacert.pem中,也无法看到验证过程。我看到一个例外:

    File "/usr/lib/python2.7/site-packages/requests/adapters.py", line 385, in send
    raise SSLError(e)
SSLError: [Errno 1] _ssl.c:504: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

我做错什么了吗?我应该只添加在服务器中签名localhost.crt的CA吗?

谢谢, 维杰


Tags: 路径服务器localhostsslserverapacheconftls