Skip to content

Commit c460013

Browse files
author
Alano Terblanche
committed
Updating dev-1.0.
1 parent 475c72b commit c460013

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

APIHandler.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class APIHandler:
2323
2424
"""
2525

26-
def __init__(self, ip: str, username: str, password: str, **kwargs):
26+
def __init__(self, ip: str, username: str, password: str, https = False, **kwargs):
2727
"""
2828
Initialise the Camera API Handler (maps api calls into python)
2929
:param ip:
@@ -34,8 +34,9 @@ def __init__(self, ip: str, username: str, password: str, **kwargs):
3434
More information on proxies in requests: https://stackoverflow.com/a/15661226/9313679
3535
3636
"""
37+
scheme = 'https' if https else 'http'
38+
self.url = f"{scheme}://{ip}/cgi-bin/api.cgi"
3739
self.ip = ip
38-
self.url = "http://" + ip + "/cgi-bin/api.cgi"
3940
self.token = None
4041
self.username = username
4142
self.password = password

Camera.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
class Camera(APIHandler):
55

6-
def __init__(self, ip, username="admin", password=""):
6+
def __init__(self, ip, username="admin", password="", https=False):
77
"""
88
Initialise the Camera object by passing the ip address.
99
The default details {"username":"admin", "password":""} will be used if nothing passed
@@ -12,11 +12,11 @@ def __init__(self, ip, username="admin", password=""):
1212
:param password:
1313
"""
1414
# For when you need to connect to a camera behind a proxy
15-
APIHandler.__init__(self, ip, username, password, proxy={"http": "socks5://127.0.0.1:8000"})
15+
APIHandler.__init__(self, ip, username, password, proxy={"http": "socks5://127.0.0.1:8000"}, https=https)
1616

1717
# Normal call without proxy:
1818
# APIHandler.__init__(self, ip, username, password)
19-
19+
2020
self.ip = ip
2121
self.username = username
2222
self.password = password

resthandle.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def post(url: str, data, params=None) -> requests.Response or None:
2020
"""
2121
try:
2222
headers = {'content-type': 'application/json'}
23-
r = requests.post(url, params=params, json=data, headers=headers, proxies=Request.proxies)
23+
r = requests.post(url, verify=False, params=params, json=data, headers=headers, proxies=Request.proxies)
2424
# if params is not None:
2525
# r = requests.post(url, params=params, json=data, headers=headers, proxies=proxies)
2626
# else:
@@ -43,7 +43,7 @@ def get(url, params, timeout=1) -> json or None:
4343
:return:
4444
"""
4545
try:
46-
data = requests.get(url=url, params=params, timeout=timeout, proxies=Request.proxies)
46+
data = requests.get(url=url, verify=False, params=params, timeout=timeout, proxies=Request.proxies)
4747

4848
return data
4949
except Exception as e:

0 commit comments

Comments
 (0)