diff --git a/APIHandler.py b/APIHandler.py index c52b624..e03379a 100644 --- a/APIHandler.py +++ b/APIHandler.py @@ -23,7 +23,7 @@ class APIHandler: """ - def __init__(self, ip: str, username: str, password: str, **kwargs): + def __init__(self, ip: str, username: str, password: str, https = False, **kwargs): """ Initialise the Camera API Handler (maps api calls into python) :param ip: @@ -34,8 +34,9 @@ class APIHandler: More information on proxies in requests: https://stackoverflow.com/a/15661226/9313679 """ + scheme = 'https' if https else 'http' + self.url = f"{scheme}://{ip}/cgi-bin/api.cgi" self.ip = ip - self.url = "http://" + ip + "/cgi-bin/api.cgi" self.token = None self.username = username self.password = password diff --git a/Camera.py b/Camera.py index 4a4ee79..1e8a52b 100644 --- a/Camera.py +++ b/Camera.py @@ -3,7 +3,7 @@ from APIHandler import APIHandler class Camera(APIHandler): - def __init__(self, ip, username="admin", password=""): + def __init__(self, ip, username="admin", password="", https=False): """ Initialise the Camera object by passing the ip address. The default details {"username":"admin", "password":""} will be used if nothing passed @@ -12,11 +12,11 @@ class Camera(APIHandler): :param password: """ # For when you need to connect to a camera behind a proxy - APIHandler.__init__(self, ip, username, password, proxy={"http": "socks5://127.0.0.1:8000"}) + APIHandler.__init__(self, ip, username, password, proxy={"http": "socks5://127.0.0.1:8000"}, https=https) # Normal call without proxy: # APIHandler.__init__(self, ip, username, password) - + self.ip = ip self.username = username self.password = password diff --git a/resthandle.py b/resthandle.py index f68f406..6921c20 100644 --- a/resthandle.py +++ b/resthandle.py @@ -20,7 +20,7 @@ class Request: """ try: headers = {'content-type': 'application/json'} - r = requests.post(url, params=params, json=data, headers=headers, proxies=Request.proxies) + r = requests.post(url, verify=False, params=params, json=data, headers=headers, proxies=Request.proxies) # if params is not None: # r = requests.post(url, params=params, json=data, headers=headers, proxies=proxies) # else: @@ -43,7 +43,7 @@ class Request: :return: """ try: - data = requests.get(url=url, params=params, timeout=timeout, proxies=Request.proxies) + data = requests.get(url=url, verify=False, params=params, timeout=timeout, proxies=Request.proxies) return data except Exception as e: