in userbeacon/vscommunicator.py [0:0]
def do_generic(self, urlpath, requestlambda, attempt=0):
"""
error-catching wrapper for an http request. Recursively retries if a timeout is received
:param urlpath: API path to hit, with a leading /. /API is not necessary, it's added automatically if it does not exist.
:param requestlambda: lambda function that performs the actual request. This is passed the full_url as a parameter
and is expected to return a Requests response object
:param attempt: attempt counter, don't set this when calling externally
:return: the json content returned as a dictionary.
If the request errors then an HttpError is raised, if it succeeds but the content won't parse as json then
a ParseException is raised
"""
if urlpath.startswith("/API"):
api_url_path = urlpath
else:
api_url_path = "/API" + urlpath
full_url = settings.VIDISPINE_BASE_URL + api_url_path
result = requestlambda(full_url)
if result.status_code==503 or result.status_code==502 or result.status_code==501:
if attempt>=self.max_retries:
logger.error("Vidispine is still not available, giving up")
raise HttpTimeoutError("Timed out accessing {0}".format(full_url))
logger.warning("Vidispine not available on attempt {0}, received {1}".format(attempt, result.status_code))
time.sleep(self.retry_wait)
return self.do_generic(urlpath, requestlambda, attempt+1)
elif result.status_code!=200 and result.status_code!=201:
raise HttpError(full_url, result.status_code, result.text, result.headers)
else:
return result.json()