如何使用 boto3 客户端删除仍然可用的 HIT

T.P*_*Poe 1 python mechanicalturk boto3

我有一些已发布的 HIT 可供工人使用。现在我想删除它们,尽管它们还没有被工人完成。根据此文档,这是不可能的:https : //boto3.amazonaws.com/v1/documentation/api/latest/reference/services/mturk.html#MTurk.Client.delete_hit

只能删除处于可审查状态的 HIT。

但是使用命令行界面似乎是可能的:https : //docs.aws.amazon.com/AWSMechTurk/latest/AWSMturkCLT/CLTReference_DeleteHITsCommand.html

我的问题是,我能否以某种方式使用 boto3 客户端完成删除不可审查的 HIT 的命令行行为?

小智 11

部分解决方案是将“可分配”HIT 设置为立即过期。我使用这个脚本来清理 Mechanical Turk 沙箱:

import boto3
from datetime import datetime

# Get the MTurk client
mturk=boto3.client('mturk',
        aws_access_key_id="aws_access_key_id",
        aws_secret_access_key="aws_secret_access_key",
        region_name='us-east-1',
        endpoint_url="https://mturk-requester-sandbox.us-east-1.amazonaws.com",
    )

# Delete HITs
for item in mturk.list_hits()['HITs']:
    hit_id=item['HITId']
    print('HITId:', hit_id)

    # Get HIT status
    status=mturk.get_hit(HITId=hit_id)['HIT']['HITStatus']
    print('HITStatus:', status)

    # If HIT is active then set it to expire immediately
    if status=='Assignable':
        response = mturk.update_expiration_for_hit(
            HITId=hit_id,
            ExpireAt=datetime(2015, 1, 1)
        )        

    # Delete the HIT
    try:
        mturk.delete_hit(HITId=hit_id)
    except:
        print('Not deleted')
    else:
        print('Deleted')
Run Code Online (Sandbox Code Playgroud)