Skip to content

Commit

Permalink
Raise proper errors in snapshot so we can tell if we need to re-login
Browse files Browse the repository at this point in the history
  • Loading branch information
kk7ds committed Feb 14, 2016
1 parent 9e20878 commit b4b3f3b
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions uvcclient/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@ class CameraConnectError(Exception):
pass


class CameraAuthError(Exception):
pass


class UVCCameraClient(object):
def __init__(self, host, username, password, port=80):
self._host = host
self._port = port
self._username = username
self._password = password
self._cookie = None
self._cookie = ''
self._log = logging.getLogger('UVCCamera(%s)' % self._host)

def _safe_request(self, *args, **kwargs):
Expand Down Expand Up @@ -73,7 +77,7 @@ def login(self):
'Cookie': self._cookie}
resp = self._safe_request('POST', '/login.cgi', data, headers)
if resp.status != 200:
raise Exception('Failed to login: %s' % resp.reason)
raise CameraAuthError('Failed to login: %s' % resp.reason)

def _cfgwrite(self, setting, value):
headers = {'Cookie': self._cookie}
Expand All @@ -93,4 +97,9 @@ def get_snapshot(self):
headers = {'Cookie': self._cookie}
resp = self._safe_request('GET', '/snapshot.cgi',
headers=headers)
if resp.status in (401, 403, 302):
raise CameraAuthError('Not logged in')
elif resp.status != 200:
raise CameraConnectError(
'Snapshot failed: %s' % resp.status)
return resp.read()

0 comments on commit b4b3f3b

Please sign in to comment.