1

I need to call api to get some data, for that I used requests:

def call_api():
   
    URL = f'......'
    API_KEY = "......"
    header = {
        "Authorization": API_KEY,
        "accept": "application/json",
        "cache-control": "no-cache",
    }

    s = requests.Session()
    s.headers = header
    s.verify = os.path.abspath("certificate.pem")
    s.mount(URL,MyAdapter())

    result = s.get(URL)
    result_json = result.json()

class MyAdapter(requests.adapters.HTTPAdapter):
    def init_poolmanager(self, connections, maxsize, block=False):
        self.poolmanager = urllib3.PoolManager(
            num_pools=connections,
            maxsize=maxsize,
            block=block,
            ssl_version=ssl.PROTOCOL_TLSv1_2,
        )

As you can see I need to give the certificate because otherwise I have the following error :

 Max retries exceeded with url: ..... (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)')))

To fix that, I downloaded the certificate chain manually with google chrome and it works. But this certificates only work for my pc, and not on others

My question is: How with python, can I download the complete certificate chain?


I have already try to get chain certificate with this post but :

  1. This method return me only 5 certificates, when I extract chain certificate with chrome I have 6 certificates
  2. Only 3 certificates match with chrome download certificates chain
Riolou
  • 11
  • 3
  • Does this answer your question? [How to get response SSL certificate from requests in python?](https://stackoverflow.com/questions/16903528/how-to-get-response-ssl-certificate-from-requests-in-python) – misraX Sep 14 '22 at 13:32
  • @misraX I must admit that I do not understand the codes presented. I still tested [this one](https://stackoverflow.com/a/16904623/18398488) but I had a ```unable to get local issuer certificate``` – Riolou Sep 14 '22 at 14:30

0 Answers0