Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# got 403, likely due to used quota
if wait_for < 300:
if wait_for < 0:
log.warning(
'Exceeded API quota. Repeating request because quota is about to '
'be reinstated'
)
else:
log.warning(
'Waiting {} seconds for API quota reinstatement'.format(wait_for)
)
time.sleep(wait_for)
self.rate_limited_count = self.rate_limited_count + 1
return self.get(url)
else:
raise ApiCredentialsError(
'Exceeded API rate limit after waiting: {}'.format(
r.json()['message'])
)
return self.get(url)
if r.status_code == 403 and url != self.get_rate_limit_url():
self.rate_limited_count = 0
return r
def get(self, url, **kwargs):
r = super(GitHubRepoSession, self).get(url, **kwargs)
if r.status_code == 401:
if self.api_token:
raise ApiCredentialsError('API request was denied despite using an API token. '
'Missing scopes?')
raise ApiCredentialsError('Denied API access. Please set GITHUB_API_TOKEN env var '
'as per https://github.com/dvershinin/lastversion#tips')
if r.status_code == 403:
if 'X-RateLimit-Reset' in r.headers and 'X-RateLimit-Remaining' in r.headers:
if self.rate_limited_count > 2:
raise ApiCredentialsError(
'API requests were denied after retrying {} times'.format(
self.rate_limited_count)
)
remaining = int(r.headers['X-RateLimit-Remaining'])
wait_for = int(r.headers['X-RateLimit-Reset']) - time.time()
if not remaining:
# got 403, likely due to used quota
if wait_for < 300:
if wait_for < 0:
log.warning(
'Exceeded API quota. Repeating request because quota is about to '
def get(self, url, **kwargs):
r = super(GitHubRepoSession, self).get(url, **kwargs)
if r.status_code == 401:
if self.api_token:
raise ApiCredentialsError('API request was denied despite using an API token. '
'Missing scopes?')
raise ApiCredentialsError('Denied API access. Please set GITHUB_API_TOKEN env var '
'as per https://github.com/dvershinin/lastversion#tips')
if r.status_code == 403:
if 'X-RateLimit-Reset' in r.headers and 'X-RateLimit-Remaining' in r.headers:
if self.rate_limited_count > 2:
raise ApiCredentialsError(
'API requests were denied after retrying {} times'.format(
self.rate_limited_count)
)
remaining = int(r.headers['X-RateLimit-Remaining'])
wait_for = int(r.headers['X-RateLimit-Reset']) - time.time()
if not remaining:
# got 403, likely due to used quota
if wait_for < 300:
if wait_for < 0: