Allow HTTPS connections with self-signed certificates
authorPlamen Dimitrov <pdimitrov@pevogam.com>
Tue, 26 Mar 2019 03:53:52 +0000 (11:53 +0800)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Tue, 9 Apr 2019 09:53:17 +0000 (11:53 +0200)
We use such certificates on the web surface of the Intra2net system.

src/web_interface.py

index 699d672..ddeb8da 100644 (file)
@@ -33,6 +33,7 @@ INTERFACE
 """
 
 import re
+import ssl
 import http.client as client
 import urllib.parse as parse
 import logging
@@ -76,7 +77,9 @@ def web_page_request(method="GET", url="/", body=None):
     headers = {"Content-Type": "application/x-www-form-urlencoded",
                "Accept": "text/plain"}
 
-    conn = client.HTTPSConnection("localhost")
+    # Allow for an HTTPS connection with self-signed certificates
+    context = ssl._create_unverified_context()
+    conn = client.HTTPSConnection("localhost", context=context)
     conn.request(method, url, body, headers)
     resp = conn.getresponse()
     logging.info("Request status %s and response %s",