Merge pull request #1 from davidjb/https

Allow API connection over HTTPS
This commit is contained in:
Alano Terblanche
2019-09-15 22:12:51 +02:00
committed by GitHub
3 changed files with 9 additions and 7 deletions

View File

@@ -5,8 +5,9 @@ from resthandle import Request
class APIHandler:
def __init__(self, ip):
self.url = "http://" + ip + "/cgi-bin/api.cgi"
def __init__(self, ip, https=False):
scheme = 'https' if https else 'http'
self.url = f"{scheme}://{ip}/cgi-bin/api.cgi"
self.token = None
# Token

View File

@@ -3,9 +3,10 @@ from APIHandler import APIHandler
class Camera(APIHandler):
def __init__(self, ip, username="admin", password=""):
APIHandler.__init__(self, ip)
def __init__(self, ip, username="admin", password="", https=False):
APIHandler.__init__(self, ip, https=https)
self.ip = ip
self.username = username
self.password = password
self.https = https
super().login(self.username, self.password)

View File

@@ -17,9 +17,9 @@ class Request:
try:
headers = {'content-type': 'application/json'}
if params is not None:
r = requests.post(url, params=params, json=data, headers=headers)
r = requests.post(url, verify=False, params=params, json=data, headers=headers)
else:
r = requests.post(url, json=data)
r = requests.post(url, verify=False, json=data)
if r.status_code == 200:
return r
else:
@@ -38,7 +38,7 @@ class Request:
:return:
"""
try:
data = requests.get(url=url, params=params, timeout=timeout)
data = requests.get(url=url, verify=False, params=params, timeout=timeout)
return data
except Exception as e:
print("Get Error\n", e)