Skip to content

Add self.retry_after to SparkRateLimitError class #49

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

Merged
merged 1 commit into from
Nov 21, 2017
Merged
Show file tree
Hide file tree
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
10 changes: 9 additions & 1 deletion ciscosparkapi/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,12 @@ def __init__(self, response):

class SparkRateLimitError(SparkApiError):
"""Cisco Spark Rate-Limit exceeded Error."""
pass

def __init__(self, response):
assert isinstance(response, requests.Response)

# Set a sane default just incase Spark lets us down
self.retry_after = 200

if 'Retry-After' in response.headers.keys():
self.retry_after = int(response.headers['Retry-After'])
2 changes: 1 addition & 1 deletion ciscosparkapi/restsession.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def request(self, method, url, erc, **kwargs):
# Wait and retry if automatic rate-limit handling is enabled
if self.wait_on_rate_limit and e.retry_after:
logger.info("Received rate-limit message; "
"waiting {:0.0f} seconds."
"waiting {0} seconds."
"".format(e.retry_after))
time.sleep(e.retry_after)
continue
Expand Down