Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added HTTPS support to nvr.py #5

Merged
merged 1 commit into from
Nov 28, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions uvcclient/nvr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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:
Expand Down