Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
else:
if query_id is not None:
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)
time.sleep(retry_seconds)
attempt_number += 1
retry_seconds = min(retry_seconds * 2, max_retry_seconds)