Merge pull request #1 from davidjb/https
Allow API connection over HTTPS
This commit is contained in:
@@ -5,8 +5,9 @@ from resthandle import Request
|
|||||||
|
|
||||||
class APIHandler:
|
class APIHandler:
|
||||||
|
|
||||||
def __init__(self, ip):
|
def __init__(self, ip, https=False):
|
||||||
self.url = "http://" + ip + "/cgi-bin/api.cgi"
|
scheme = 'https' if https else 'http'
|
||||||
|
self.url = f"{scheme}://{ip}/cgi-bin/api.cgi"
|
||||||
self.token = None
|
self.token = None
|
||||||
|
|
||||||
# Token
|
# Token
|
||||||
|
|||||||
@@ -3,9 +3,10 @@ from APIHandler import APIHandler
|
|||||||
|
|
||||||
class Camera(APIHandler):
|
class Camera(APIHandler):
|
||||||
|
|
||||||
def __init__(self, ip, username="admin", password=""):
|
def __init__(self, ip, username="admin", password="", https=False):
|
||||||
APIHandler.__init__(self, ip)
|
APIHandler.__init__(self, ip, https=https)
|
||||||
self.ip = ip
|
self.ip = ip
|
||||||
self.username = username
|
self.username = username
|
||||||
self.password = password
|
self.password = password
|
||||||
|
self.https = https
|
||||||
super().login(self.username, self.password)
|
super().login(self.username, self.password)
|
||||||
|
|||||||
@@ -17,9 +17,9 @@ class Request:
|
|||||||
try:
|
try:
|
||||||
headers = {'content-type': 'application/json'}
|
headers = {'content-type': 'application/json'}
|
||||||
if params is not None:
|
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:
|
else:
|
||||||
r = requests.post(url, json=data)
|
r = requests.post(url, verify=False, json=data)
|
||||||
if r.status_code == 200:
|
if r.status_code == 200:
|
||||||
return r
|
return r
|
||||||
else:
|
else:
|
||||||
@@ -38,7 +38,7 @@ class Request:
|
|||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
data = requests.get(url=url, params=params, timeout=timeout)
|
data = requests.get(url=url, verify=False, params=params, timeout=timeout)
|
||||||
return data
|
return data
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Get Error\n", e)
|
print("Get Error\n", e)
|
||||||
|
|||||||
Reference in New Issue
Block a user