RETRYABLE = {
"ERROR_SERVICE_UNAVALIABLE",
"ERROR_DATABASE_UNAVAILABLE",
"ERROR_PROXY_CONNECTION",
"ERROR_THREAD_THRESHOLD_EXCEEDED",
"ERROR_SOLVE_TIMEOUT",
"ERROR_PROCESSING_IMAGE",
}
def create_task_safe(client_key, task, max_retries=3):
for attempt in range(max_retries):
resp = requests.post("https://api.funbypass.com/createTask", json={
"clientKey": client_key,
"task": task
})
data = resp.json()
if data.get("errorId", 0) == 0:
return data
error_code = data.get("errorCode", "")
if error_code in RETRYABLE:
time.sleep(2 ** attempt)
continue
raise Exception(f"{error_code}: {data.get('errorDescription')}")
raise Exception("Max retries exceeded")