gpt4 book ai didi

python - python中的这个ssl错误是什么意思?

转载 作者:太空宇宙 更新时间:2023-11-04 09:15:03 28 4
gpt4 key购买 nike

我有以下简单的 python 代码,旨在执行 ssl 握手并验证客户端和服务器之间的证书:

ssl_test.py:

import ssl
import socket

s = socket.socket()
print "connecting..."
#logging.debug("Connecting")
# Connect with SSL mutual authentication
# We only trust our server's CA, and it only trusts user certificates signed by it
c = ssl.wrap_socket(s, cert_reqs=ssl.CERT_REQUIRED,
ssl_version=ssl.PROTOCOL_SSLv3, ca_certs='ca.crt',
certfile='user.crt', keyfile='user.key')
c.connect((constants.server_addr, constants.port))

执行此操作时,出现以下错误。

>python ssl_test.py
Traceback (most recent call last):
File "ssl_test.py", line 12, in <module>
c.connect(('192.168.1.82', 7070))
File "C:\Python27\lib\ssl.py", line 331, in connect
self._real_connect(addr, False)
File "C:\Python27\lib\ssl.py", line 314, in _real_connect
self.ca_certs, self.ciphers)
ssl.SSLError: [Errno 0] _ssl.c:340: error:00000000:lib(0):func(0):reason(0)

这个错误是什么意思,我该如何解决?

最佳答案

这看起来像 http://bugs.python.org/issue2687 ,其中给出了以下答案:

No, the problem is with your "ca_certs" argument on the client side. You can't use a directory. You must use a file containing a number of concatenated certificates. I'll beef up the documentation to make that clearer.

我看到您的 ca_certs 是一个文件,而不是一个目录,但也许这仍然能说明一些问题。 ca.crt 文件的格式是否正确且位置正确?

关于python - python中的这个ssl错误是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10640546/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com