使用python httplib违反协议时发生SSL EOF

时间:2012-12-13 19:10:14

标签: ssl certificate httplib httpserver

关于这个主题的当前问题并没有解决我的问题,谷歌也没有。

相关服务器代码:

class ReuseHTTPServer(BaseHTTPServer.HTTPServer):
    def __init__(self, address, handler, queue=None):
        BaseHTTPServer.HTTPServer.__init__(self, address, handler)

        self.address = address
        ssl_socket = ssl.wrap_socket(socket.socket(self.address_family, self.socket_type),
                                     keyfile = KEY_PATH,
                                     certfile = CERTIFICATE_PATH,
                                     server_side = True,
                                     cert_reqs = ssl.CERT_REQUIRED,
                                     ssl_version = ssl.PROTOCOL_TLSv1,
                                     ca_certs = CA_PATH)
        s = self.socket.getsockname()

        print "serving:", s[0], "on port:", s[1]

        self.socket = ssl_socket

        self.server_bind()
        self.server_activate()

客户代码:

conn = https.HTTPSConnection(HOST, port=PORT, key_file=KEY_PATH, cert_file=CERT_PATH)

        conn.putrequest("GET", '/cgi-bin/retrieveRunningInstances')

        conn.endheaders()

        response = conn.getresponse()

尝试与客户端连接获取SSLError errno 8; EOF违反协议发生。我已经使用openssl验证了证书。我把头发拉了出来。任何帮助将不胜感激。

编辑:

conn.getresponse()握手期间发生错误。

1 个答案:

答案 0 :(得分:0)

我想我明白了。我遇到了同样的问题:

SSLError errno 8; EOF occurred in violation of protocol

原来我丢失了cert_file。我已经指定了一个如下,但没有一个。

server = HTTPServer( ('',5005), HttpHandler )
server.socket = ssl.wrap_socket( server.socket, certfile='kencert.pem', server_side=True )

当我添加.pem文件时,它有效!

希望这有帮助!