in src/plugins/utils/jsonapi.py [0:0]
def get(url, cookie = None, auth = None, token = None, retries = 5, timeout = 30):
headers = {
"Content-type": "application/json",
"Accept": "application/json",
"User-Agent": "Apache Kibble",
}
if auth:
xcreds = auth.encode(encoding='ascii', errors='replace')
bauth = base64.encodebytes(xcreds).decode('ascii', errors='replace').replace("\n", '')
headers["Authorization"] = "Basic %s" % bauth
if token:
headers["Authorization"] = "token %s" % token
if cookie:
headers["Cookie"] = cookie
rv = requests.get(url, headers = headers, timeout = (CONNECT_TIMEOUT, timeout))
# Some services may be rate limited. We'll try sleeping it off in 60 second
# intervals for a max of five minutes, then give up.
if rv.status_code == 429:
if retries > 0:
time.sleep(60)
retries -= 1
return get(url, cookie = cookie, auth = auth, token = token, retries = retries, timeout = timeout)
if rv.status_code < 400:
return rv.json()
raise requests.exceptions.ConnectionError("Could not fetch JSON, server responded with status code %u" % rv.status_code, response = rv)