How to use the jwplatform.errors.JWPlatformRateLimitExceededError function in jwplatform

To help you get started, we’ve selected a few jwplatform examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jwplayer / jwplatform-py / tests / test_errors.py View on Github external
'status': 'error',
            'code': 'SignatureInvalid',
            'title': 'Signature Invalid',
            'message': '400'
        },
        'expected_exception': jwplatform.errors.JWPlatformSignatureInvalidError
    },
    {
        'http_status': 429,
        'response': {
            'status': 'error',
            'code': 'RateLimitExceeded',
            'title': 'Rate Limit Exceeded',
            'message': ''
        },
        'expected_exception': jwplatform.errors.JWPlatformRateLimitExceededError
    },
    {
        'http_status': 500,
        'response': {
            'status': 'error',
            'message': 'New unhandled error',
            'code': 'NewError',
            'title': 'New Error'
        },
        'expected_exception': jwplatform.errors.JWPlatformUnknownError
    }
]


@responses.activate
@pytest.mark.parametrize('test_case', SUPPORTED_ERROR_CASES)
github jwplayer / jwplatform-py / examples / video_list_to_csv.py View on Github external
path_to_csv = path_to_csv or os.path.join(os.getcwd(), 'video_list.csv')
    timeout_in_seconds = 2
    max_retries = 3
    retries = 0
    offset = 0
    videos = list()

    jwplatform_client = jwplatform.Client(api_key, api_secret)
    logging.info("Querying for video list.")

    while True:
        try:
            response = jwplatform_client.videos.list(result_limit=result_limit,
                                                     result_offset=offset,
                                                     **kwargs)
        except jwplatform.errors.JWPlatformRateLimitExceededError:
            logging.error("Encountered rate limiting error. Backing off on request time.")
            if retries == max_retries:
                raise jwplatform.errors.JWPlatformRateLimitExceededError()
            timeout_in_seconds *= timeout_in_seconds  # Exponential back off for timeout in seconds. 2->4->8->etc.etc.
            retries += 1
            time.sleep(timeout_in_seconds)
            continue
        except jwplatform.errors.JWPlatformError as e:
            logging.error("Encountered an error querying for videos list.\n{}".format(e))
            raise e

        # Reset retry flow-control variables upon a non successful query (AKA not rate limited)
        retries = 0
        timeout_in_seconds = 2

        # Add all fetched video objects to our videos list.