Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
sleep(1)
r = requests.post(url, json=data, headers=header)
else:
raise NotImplementedError('method: ' + method + ' not implemented.')
if r.status_code == 504: # Gateway Time-out
if time_out_counter == 99:
msg = 'Server not responding in time'
raise requests.ConnectionError(msg)
time_out_counter += 1
continue
time_out_counter = 0
if r.status_code == 401:
raise OpenCgaInvalidToken(r.content)
elif r.status_code == 403:
raise OpenCgaAuthorisationError(r.content)
elif r.status_code != 200:
raise Exception(r.content)
try:
response = r.json()
except ValueError:
msg = 'Bad JSON format retrieved from server'
raise ValueError(msg)
# Setting up final_response
if final_response is None:
final_response = response
# Concatenating results
results in an error because the sessionId is invalid, login_handler()
will be called and this failed attempt will not count towards the maximum
of attempts
:param on_retry: a callback to be called before retrying. Must accept 3 parameters:
exception value, exception type, traceback.
:param dont_retry: optional; List of strings, if any are present in the exception
message don't retry
:return: the result of func() if successful, otherwise the last exception raised
by calling func.
"""
attempt_number = 1
retry_seconds = initial_retry_seconds
while True:
try:
return func()
except OpenCgaInvalidToken as e:
if login_handler:
login_handler()
else:
raise e
except OpenCgaAuthorisationError as e:
raise e
except Exception as e:
if dont_retry and any(string_ in str(e) for string_ in dont_retry):
raise e
if attempt_number >= max_attempts: # last attempt failed, propagate error:
raise
if on_retry:
# notify that we are retrying
exc_type, exc_val, exc_tb = sys.exc_info()
on_retry(exc_type, exc_val, exc_tb)