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

Handle rate limit: retry after requested delay #378

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -41,6 +41,7 @@
import Consts
import re
import os
import time

atLeastPython26 = sys.hexversion >= 0x02060000
atLeastPython3 = sys.hexversion >= 0x03000000
@@ -168,7 +169,16 @@ def __init__(self, login_or_token, password, base_url, timeout, client_id, clien
self.__apiPreview = api_preview

def requestJsonAndCheck(self, verb, url, parameters=None, headers=None, input=None, cnx=None):
return self.__check(*self.requestJson(verb, url, parameters, headers, input, cnx))
for i in range(3):
try:
(status, responseHeaders, output) = self.requestJson(verb, url, parameters, headers, input, cnx)
return self.__check(status, responseHeaders, output)
except GithubException.RateLimitExceededException:
delay = int(responseHeaders['x-ratelimit-reset']) - int(time.time())
logger = logging.getLogger(__name__)
logger.warning("rate limit reached, sleeping for %d seconds" % delay)
time.sleep(delay+1)
raise # couldn't get an answer after 3 attempts

def requestMultipartAndCheck(self, verb, url, parameters=None, headers=None, input=None):
return self.__check(*self.requestMultipart(verb, url, parameters, headers, input))
@@ -186,7 +196,7 @@ def __createException(self, status, headers, output):
cls = GithubException.TwoFactorException # pragma no cover (Should be covered)
elif status == 403 and output.get("message").startswith("Missing or invalid User Agent string"):
cls = GithubException.BadUserAgentException
elif status == 403 and output.get("message").startswith("API Rate Limit Exceeded"):
elif status == 403 and output.get("message").startswith("API rate limit exceeded"):
cls = GithubException.RateLimitExceededException
elif status == 404 and output.get("message") == "Not Found":
cls = GithubException.UnknownObjectException
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.