How to use the jwplatform.errors 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': 'NotFound',
            'title': 'Not Found',
            'message': 'Item not found'
        },
        'expected_exception': jwplatform.errors.JWPlatformNotFoundError
    },
    {
        'http_status': 400,
        'response': {
            'status': 'error',
            'code': 'NoMethod',
            'title': 'No Method Specified',
            'message': ''
        },
        'expected_exception': jwplatform.errors.JWPlatformNoMethodError
    },
    {
        'http_status': 501,
        'response': {
            'status': 'error',
            'code': 'NotImplemented',
            'title': 'Method Not Implemented',
            'message': ''
        },
        'expected_exception': jwplatform.errors.JWPlatformNotImplementedError
    },
    {
        'http_status': 405,
        'response': {
            'status': 'error',
            'code': 'NotSupported',
github jwplayer / jwplatform-py / examples / video_s3_update.py View on Github external
:param api_secret:  JWPlatform shared-secret
    :param local_video_path:  Path to media on local machine.
    :param video_key:  Video's object ID. Can be found within JWPlayer Dashboard.
    :param kwargs: Arguments conforming to standards found @ https://developer.jwplayer.com/jw-platform/reference/v1/methods/videos/create.html
    :return:
    """
    # Setup API client
    jwplatform_client = jwplatform.Client(api_key, api_secret)
    logging.info("Updating Video")
    try:
        response = jwplatform_client.videos.update(
            video_key=video_key,
            upload_method='s3',
            update_file='True',
            **kwargs)
    except jwplatform.errors.JWPlatformError as e:
        logging.error("Encountered an error updating the video\n{}".format(e))
        sys.exit(e.message)
    logging.info(response)

    # Construct base url for upload
    upload_url = '{}://{}{}'.format(
        response['link']['protocol'],
        response['link']['address'],
        response['link']['path']
    )

    # Query parameters for the upload
    query_parameters = response['link']['query']

    # HTTP PUT upload using requests
    with open(local_video_path, 'rb') as f:
github jwplayer / jwplatform-py / examples / video_s3_create.py View on Github external
:param api_key:  JWPlatform api-key
    :param api_secret:  JWPlatform shared-secret
    :param local_video_path:  Path to media on local machine.
    :param kwargs: Arguments conforming to standards found @ https://developer.jwplayer.com/jw-platform/reference/v1/methods/videos/create.html
    :return:
    """
    filename = os.path.basename(local_video_path)

    # Setup API client
    jwplatform_client = jwplatform.Client(api_key, api_secret)

    # Make /videos/create API call
    logging.info("creating video")
    try:
        response = jwplatform_client.videos.create(upload_method='s3', **kwargs)
    except jwplatform.errors.JWPlatformError as e:
        logging.error("Encountered an error creating a video\n{}".format(e))
        sys.exit(e.message)
    logging.info(response)

    # Construct base url for upload
    upload_url = '{}://{}{}'.format(
        response['link']['protocol'],
        response['link']['address'],
        response['link']['path']
    )

    # Query parameters for the upload
    query_parameters = response['link']['query']

    # HTTP PUT upload using requests
    headers = {'Content-Disposition': 'attachment; filename="{}"'.format(filename)}
github jwplayer / jwplatform-py / examples / video_list_to_csv.py View on Github external
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.
        next_videos = response.get('videos', [])
        last_query_total = response.get('total', 0)
        videos.extend(next_videos)
        offset += len(next_videos)
        logging.info("Accumulated {} videos.".format(offset))
        if offset >= last_query_total:  # Condition which defines you've reached the end of the library
            break