I am trying to send a request to a REST API using an SSL certificate. Following is the code snippet I have written:
import requests
import os
url = "https://ip_address/api"
headers = {
'Authorization': 'Bearer bearer_token'
}
path = os.path.join("/","tmp")
response = requests.request("GET", url, headers=headers, verify=os.path.join(path, "certfile.pem"))
print(response.status_code)
print(response.content)
I tried to run this on my local machine in a virtual environment and in the docker container as well. It worked fine.
Following are the configurations on my local machine:
Virtual Environment:
- OS: Ubuntu 22.04.1 LTS
- Python version: 3.10.6
Docker container:
- Python version: 3.10.4
This same script I tried to run on one of the servers and my first colleague's Windows 11 within windows as well as in WSL. It worked fine there too.
- Server 1 configurations:
- OS: Ubuntu 20.04
- Python version: 3.10
Following are the configurations on his machine:
- Windows 11:
- Python version: 3.9.6
- WSL:
- OS: Ubuntu 22.04.1 LTS
- Python version: 3.10.6
But this same script does not work on the other colleague's machine as well as on the servers.
The following are the configurations on These machines:
- Second colleague:
- OS: Ubuntu 22.04
- Python version: 3.8 and 3.9
- Third colleague:
- OS: Ubuntu 22.04
- Python version: 3.9 and 3.6
- Server 2 (QRadar):
- OS: RHEL
- python version: 3.6
- Server 3:
- OS: Ubuntu 22.04
- Python version: 3.8
In all the above machines we are getting the following error:
requests.exceptions.SSLError: HTTPSConnectionPool(host='xx.xx.xx.xxx', port=443): Max retries exceeded with url: /api/users/self (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:877)'),))
We have tried to run the script using requests
, urllib3
, and httpx
to figure out why.
Every time the result is the same.
It works with any of these libraries on the machine where it worked the first time. On the machine where it gave an error, it gives an error with all of these.
What could be the issue here?