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

Fix command error handling after last retry #103

Merged
merged 1 commit into from
Mar 2, 2019
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
21 changes: 7 additions & 14 deletions src/amcrest/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,7 @@ def command(self, cmd, retries=None, timeout_cmd=None):
session.mount('https://', HTTPAdapter(max_retries=self._retries_conn))

url = self.__base_url(cmd)
resp = None
loop = 0
while loop <= self._retries_conn:
loop += 1
for loop in range(1, 2 + self._retries_conn):
_LOGGER.debug("Running query attempt %s", loop)
try:
resp = session.get(
Expand All @@ -157,16 +154,12 @@ def command(self, cmd, retries=None, timeout_cmd=None):
resp.raise_for_status()
break
except requests.HTTPError as error:
_LOGGER.debug("Trying again due error %s", error)
continue

# keep the loop when 401
if resp.status_code == 401:
continue

# if we got here, let's raise because it did not work
if resp is None:
raise ValueError('Something went wrong!!!!')
if loop <= self._retries_conn:
_LOGGER.warning("Trying again due to error %s", error)
continue
else:
_LOGGER.error("Query failed due to error %s", error)
raise

_LOGGER.debug("Query worked. Exit code: <%s>", resp.status_code)
return resp
Expand Down