Handling HTTP Errors#


When running commands supported by Platform SDK, various errors may occur. If frequently met with HTTP errors you may want to wrap your command in a try-except block in combination with a while-loop. An example of how that may look:

import time
# Basic retry with exponential backoff
attempts = 0
max_attempts = 3
wait_time = 1  # Start with 1 second
while attempts < max_attempts:
    try:
        sch.start_job(job)  # function you want to retry
        logger.info("Job started successfully!")
        break  # Success!
    except HTTPException as e:
        attempts += 1
        logger.warning(f"Attempt {attempts} failed: {e}")
        if attempts < max_attempts:
            # Exponential backoff: 1s, 2s, 4s, 8s...
            wait_time = wait_time * 2
            logger.info(f"Retrying in {wait_time} seconds...")
            time.sleep(wait_time)
        else:
            logger.error("All attempts failed!")
            raise

Things to consider:#

  • When hitting rate-limiting exceptions (HTTP 429), try using high max_attempts and longer wait_time values.

  • What error codes are getting returned.