首页 > 解决方案 > 无法验证 CA 签署的 SSL 证书 python web 服务器

问题描述

这是我的 python web 服务器的示例代码:

Python Web 服务器代码(非完整版)

class LogRequests(BaseHTTPRequestHandler):

    def do_GET(self):
        print("GET request received from {}".format(self.client_address[0]))
        self.write_response(200, {"success": True})

    def do_POST(self):
        print("GET request received from {}".format(self.client_address[0]))
        self.write_response(200, {"success": True})

    def write_response(self, status_code, json_body):
        self.send_response(status_code)
        self.send_header('Content-type', 'application/json')
        self.end_headers()
        self.write_json(json_body)


server = HTTPServer(('', 6000), LogRequests)

server.socket = ssl.wrap_socket(server.socket, keyfile=<key-file-path>, certfile=<cert-file-path>, server_side=True)
server.serve_forever()

我有 CA(让我们加密)签名证书。我还使用https://support.acquia.com/hc/en-us/articles/360004119234-Verifying-the-validity-of-an-SSL-certificate验证了 cert.pem 和 key.pem 文件的有效性.

邮递员要求

URL: https://<hostname>:6000/

当我提交 POST 或 GET 请求时,它会显示SSL Error: Unable to verify the first certificate错误。但是当我禁用SSL certificate verificationPostman 设置时,我可以提出请求并获得响应。

你能指导我这里有什么问题吗?有任何代码问题吗?

标签: pythonsslhttpsssl-certificate

解决方案


我必须自己找到解决方案。

cert.pem我不得不使用文件而不是fullchain1.pem文件。


推荐阅读