From a635d3ec40dbc93b63203338557f407cd591d8e0 Mon Sep 17 00:00:00 2001 From: Carlos Gustavo Sarmiento Date: Tue, 27 Nov 2018 15:30:01 -0800 Subject: [PATCH] Added HTTPS support to nvr.py --- uvcclient/nvr.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/uvcclient/nvr.py b/uvcclient/nvr.py index 735260f..db60c21 100755 --- a/uvcclient/nvr.py +++ b/uvcclient/nvr.py @@ -51,10 +51,11 @@ class UVCRemote(object): """Remote control client for Ubiquiti Unifi Video NVR.""" CHANNEL_NAMES = ['high', 'medium', 'low'] - def __init__(self, host, port, apikey, path='/'): + def __init__(self, host, port, apikey, path='/', ssl=False): self._host = host self._port = port self._path = path + self._ssl = ssl if path != '/': raise Invalid('Path not supported yet') self._apikey = apikey @@ -80,10 +81,16 @@ def camera_identifier(self): return 'id' else: return 'uuid' + + def _get_http_connection(self): + if self._ssl: + return httplib.HTTPSConnection(self._host, self._port) + else: + return httplib.HTTPConnection(self._host, self._port) def _safe_request(self, *args, **kwargs): try: - conn = httplib.HTTPConnection(self._host, self._port) + conn = self._get_http_connection(); conn.request(*args, **kwargs) return conn.getresponse() except OSError: @@ -102,7 +109,7 @@ def _uvc_request(self, *args, **kwargs): def _uvc_request_safe(self, path, method='GET', data=None, mimetype='application/json'): - conn = httplib.HTTPConnection(self._host, self._port) + conn = self._get_http_connection(); if '?' in path: url = '%s&apiKey=%s' % (path, self._apikey) else: