I've just upgraded to the 6.0 version of Pi-hole. I have a Python program that accesses the API which shows the Pi-hole details on a display. Additionally it allows you to push a button to disable the Pi-hole for 60 seconds.
I get everything to work properly but I get a warning using the following code:
api_payload = {"password": "MY_API_PASSWORD"}
rx = requests.request("POST", 'https://192.168.3.161/api/auth', json=api_payload, verify=False)
The warning is: /home/pi/python/.env/lib/python3.11/site-packages/urllib3/connectionpool.py:1097: InsecureRequestWarning: Unverified HTTPS request is being made to host '192.168.3.161'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings
Now I want to add certificate verification as recommended. I have tried different ways to access the API with certificates but I keep getting errors.
The Pi-hole standard automatic generated certificate, which are stored in /etc/pihole/ and are the following:
-rw-rw---- 1 pihole pihole 733 Feb 18 19:14 tls_ca.crt
-rw-rw---- 1 pihole pihole 713 Feb 18 19:14 tls.crt
-rw-rw---- 1 pihole pihole 1001 Feb 18 19:14 tls.pem
I'm tried using the combination of certificates above to get it to work but no success.
server_cert_path = 'tls_ca.crt'
rx = requests.request("POST", 'https://192.168.3.161/api/auth', json=api_payload, verify=server_cert_path)
Or
server_cert_path = 'tls_ca.crt'
cert_path = 'tls.crt'
rx = requests.request("POST", 'https://192.168.3.161/api/auth', json=api_payload, verify=server_cert_path, cert=cert_path)
Or
cert_path = 'tls.crt'
rx = requests.request("POST", 'https://192.168.3.161/api/auth', json=api_payload, cert=cert_path)
one of the errors I'm getting is this:
Unexpected error: HTTPSConnectionPool(host='192.168.3.161', port=443): Max retries exceeded with url: /api/auth (Caused by SSLError(SSLCertVerificationError(1, "[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: IP address mismatch, certificate is not valid for '192.168.3.161'. (_ssl.c:992)")))
Can any please help me out or direct me to some examples?
