首页 > 解决方案 > 列出所有地面标记作业 Boto3-Python

问题描述

我正在尝试使用boto3and sagemakerwith ' list_labeling_jobs' 功能获得所有真实标签工作。但是,即使我有一个' NextToken',每次运行它时我都会得到不同的结果。我不确定是什么导致了这种行为。(注意-我尝试了节流错误的异常)

这是我的代码,

sg_mkr_client = boto3.client('sagemaker')

sample = []

tries = 0
nextToken = None
try:
    while True:
        print("Token value", nextToken)
        # Pagintae labeling jobs, so we can access all labeling jobs
        paginator = sg_mkr_client.get_paginator('list_labeling_jobs')

        
        one_submitted_jobs = paginator.paginate(
                                CreationTimeAfter=datetime.datetime(2020, 2, 10),
                                CreationTimeBefore=datetime.datetime(2020, 8, 24),
                                LastModifiedTimeAfter=datetime.datetime(2020, 2, 10),
                                LastModifiedTimeBefore=datetime.datetime(2020, 8, 24),
                                SortBy='CreationTime',
                                SortOrder='Descending',
                                StatusEquals='Completed',
                                PaginationConfig={
#                                             'MaxItems': 200,
#                                             'PageSize': 100,
                                            'NextToken': nextToken
                                        }
                )
        for m in one_submitted_jobs:
            for index, i in enumerate(m['LabelingJobSummaryList']):
#                 print(index)
                sample.append([i['LabelingJobName'], i['LabelingJobArn'], i['CreationTime'],  i['LastModifiedTime']])        
        
            nextToken = m['NextToken']
            print('getting next token')

            
except ClientError as exception_obj:
    if exception_obj.response['Error']['Code'] == 'ThrottlingException':
        print("Throttling Exception Occured.")
        print("Retrying.....")
        print("Attempt No.: " + str(tries))
        time.sleep(3)
        tries +=1
    else:
        raise

任何通过 truncate 和 nexttoken 挑战的帮助都会很棒。

标签: python-3.xamazon-web-servicesboto3amazon-sagemaker

解决方案


推荐阅读