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 :
- This method return me only 5 certificates, when I extract chain certificate with chrome I have 6 certificates
- Only 3 certificates match with chrome download certificates chain