从文档的Python SSL示例给出“通过对等连接重置”错误(Python SSL example

2019-08-22 00:19发布

我试图运行的文档中提供的示例代码ssl这里模块: http://docs.python.org/2/library/ssl.html#client-side-operation

服务器端代码是类似于本文档中给出的例子,并且它引发此异常:

Traceback (most recent call last):
  File "serve.py", line 16, in <module>
    ssl_version=ssl.PROTOCOL_TLSv1)
  File "/usr/lib/python2.7/ssl.py", line 381, in wrap_socket
    ciphers=ciphers)
  File "/usr/lib/python2.7/ssl.py", line 143, in __init__
    self.do_handshake()
  File "/usr/lib/python2.7/ssl.py", line 305, in do_handshake
    self._sslobj.do_handshake()
socket.error: [Errno 104] Connection reset by peer

而客户端代码,也类似于文档中的例子,引发此异常:

Traceback (most recent call last):
  File "client.py", line 8, in <module>
    ssl_sock.connect((host, port))
  File "/usr/lib/python2.7/ssl.py", line 331, in connect
    self._real_connect(addr, False)
  File "/usr/lib/python2.7/ssl.py", line 324, in _real_connect
    raise e
socket.error: [Errno 104] Connection reset by peer

据我所看到的,我已经复制文档中提供相当紧密的例子,所以我不知道是什么问题。 我所有的TCP,UDP和ICMP端口是开放的,所以我不认为这是一个防火墙问题。

(我已经编辑了这个问题削减了我的简码,因为它确实是相当类似的链接提供的例子,如果你想看到我的代码,看看这个问题的历史。)

Answer 1:

我发现这个问题。 我生成私钥和使用命令这样的证书:

$ openssl req -new -x509 -days 365 -nodes -out cert.pem -keyout key.pem
Generating a 1024 bit RSA private key
# ...
Country Name (2 letter code) [AU]:US
State or Province Name (full name) [Some-State]:MyState
Locality Name (eg, city) []:Some City
Organization Name (eg, company) [Internet Widgits Pty Ltd]:My Organization, Inc.
Organizational Unit Name (eg, section) []:My Group
Common Name (eg, YOUR name) []:myserver.mygroup.myorganization.com
Email Address []:ops@myserver.mygroup.myorganization.com
$

最关键的部分是,“通用名称”中输入必须的服务器的域名相匹配。 我认为,当cacertsssl.CERT_NONE ,它是默认wrap_socket ,这将不会被检查,但我错了。 它总是检查。 一个晚上的睡眠,这是我想到的验证的第一件事!

希望这将是别人谁得到这个神秘的错误信息是有用的。

如果不解决这个问题,你可以从深度包检测症。 我再次得到这个错误时,我是一所大学的网络上,而不是任何其他网络上,我敢肯定,这是因为深度包检测。



文章来源: Python SSL example from docs gives “Connection reset by peer” error
标签: python ssl