[Python] Python request to second endpoint fails after using client certificate to first...

Discussão em 'Python' iniciado por Stack, Setembro 27, 2024.

  1. Stack

    Stack Membro Participativo

    I am using Python's requests package to make API calls. I have two different API endpoints I am making calls against. The first is to "https://api.example.com" and the second is to "https://work.myserver.com". The first API endpoint requires the use of a client certificate while the second does not. I find that once I make the call to the endpoint that requires the client certificate subsequent calls to the other endpoint fail with the error "SSLError(SSLError(1, '[SSL: TLSV1_ALERT_UNKNOWN_CA] tlsv1 alert unknown ca".

    My guess is that after I have made a call using a client certificate all the calls that come after no matter to which endpoint are made using the client certificate.

    How do I tell requests to not use the client certificate for all the other endpoints, and only to use it for the endpoint that requires it?

    My code looks like this:

    import requests

    # Set up the key-pair paths
    cert_path = "/etc/application/client.crt"
    key_path = "/etc/application/client.key"
    keypair_paths = (cert_path, key_path)

    response1 = requests.get(
    "https://api.example.com",
    cert=keypair_paths,
    )

    response2 = request.get("https://work.myserver.com") # This endpoint does NOT use client certificates

    Continue reading...

Compartilhe esta Página