Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #51 from cpainchaud/main
Browse files Browse the repository at this point in the history
fixed a crash with inconsistent API results with Search command
  • Loading branch information
cpainchaud authored Oct 15, 2021
2 parents aea4674 + 1928300 commit 6f53235
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions reolink/camera_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1010,9 +1010,10 @@ async def send_search(
if json_data[0]["code"] == 0:
search_result = json_data[0]["value"]["SearchResult"]
if only_status or "File" not in search_result:
return search_result["Status"], None

return search_result["Status"], search_result["File"]
if "Status" in search_result:
return search_result["Status"], None
else:
return search_result["Status"], search_result["File"]

_LOGGER.warning("Host: %s: Failed to get results for %s, JSON data was was empty?", self._host, command)
return None, None
Expand Down Expand Up @@ -1067,9 +1068,9 @@ async def send(self, body, param=None, expected_content_type: Optional[str] = No
try:
if body is None:
async with self._aiohttp_session.get(url=self._url, params=param, allow_redirects=False) as response:
_LOGGER.debug("send() HTTP3 Request params =%s", str(param).replace(self._password, "<password>"))
_LOGGER.debug("send() HTTP Request params =%s", str(param).replace(self._password, "<password>"))
json_data = await response.read()
_LOGGER.debug("send() HTTP3 Response status=%s content-type=(%s)",
_LOGGER.debug("send() HTTP Response status=%s content-type=(%s)",
response.status, response.content_type)

if param.get("cmd") == "Snap":
Expand All @@ -1078,7 +1079,7 @@ async def send(self, body, param=None, expected_content_type: Optional[str] = No
_LOGGER_DATA.debug("send() HTTP Response data: %s", json_data)

if len(json_data) < 500 and response.content_type == 'text/html':
if b'"detail" : "invalid user"' in json_data or b'"detail" : "login failed"' in json_data:
if b'"detail" : "invalid user"' in json_data or b'"detail" : "login failed"' in json_data or b'detail" : "please login first' in json_data:
self.clear_token()
raise CredentialsInvalidError()

Expand All @@ -1101,7 +1102,7 @@ async def send(self, body, param=None, expected_content_type: Optional[str] = No
_LOGGER_DATA.debug("send() HTTP Response data: %s", json_data)

if len(json_data) < 500 and response.content_type == 'text/html':
if '"detail" : "invalid user"' in json_data or '"detail" : "login failed"' in json_data:
if 'detail" : "invalid user' in json_data or 'detail" : "login failed' in json_data or 'detail" : "please login first' in json_data:
self.clear_token()
raise CredentialsInvalidError()

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
setup(
name='reolink',
packages=['reolink'],
version='0.0.29',
version='0.0.30',
license='MIT',
description='Reolink camera package',
author='fwestenberg',
Expand Down

0 comments on commit 6f53235

Please sign in to comment.