{"id":"cf7607f72f47cd8e","repo":"redis/redis-py","slug":"received-and-expected-certificates-do-not-match","errorCode":null,"errorMessage":"received and expected certificates do not match","messagePattern":"received and expected certificates do not match","errorType":"exception","errorClass":"ConnectionError","httpStatus":null,"severity":"error","filePath":"redis/ocsp.py","lineNumber":165,"sourceCode":"    \"\"\"\n    if ocsp_bytes in [b\"\", None]:\n        raise ConnectionError(\"no ocsp response present\")\n\n    issuer_cert = None\n    peer_cert = con.get_peer_certificate().to_cryptography()\n    for c in con.get_peer_cert_chain():\n        cert = c.to_cryptography()\n        if cert.subject == peer_cert.issuer:\n            issuer_cert = cert\n            break\n\n    if issuer_cert is None:\n        raise ConnectionError(\"no matching issuer cert found in certificate chain\")\n\n    if expected is not None:\n        e = x509.load_pem_x509_certificate(expected)\n        if peer_cert != e:\n            raise ConnectionError(\"received and expected certificates do not match\")\n\n    return _check_certificate(issuer_cert, ocsp_bytes)\n\n\nclass OCSPVerifier:\n    \"\"\"A class to verify ssl sockets for RFC6960/RFC6961. This can be used\n    when using direct validation of OCSP responses and certificate revocations.\n\n    @see https://datatracker.ietf.org/doc/html/rfc6960\n    @see https://datatracker.ietf.org/doc/html/rfc6961\n    \"\"\"\n\n    def __init__(self, sock, host, port, ca_certs=None):\n        self.SOCK = sock\n        self.HOST = host\n        self.PORT = port\n        self.CA_CERTS = ca_certs\n","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/ocsp.py#L147-L183","documentation":"Error \"received and expected certificates do not match\" thrown in redis/redis-py.","triggerScenarios":"Thrown at redis/ocsp.py:165 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}