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

标签 python boto3 mechanicalturk

我有一些已发布的 HIT 可供工作人员使用。现在我想删除它们,尽管它们还没有被 worker 完成。根据此文档,这是不可能的: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 的命令行行为?

最佳答案

部分解决方案是将“可分配”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')

关于python - 如何使用 boto3 客户端删除仍然可用的 HIT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54198700/

相关文章:

python - 使用 Python Matlibplot 和 im.show() 显示图像,为什么它们不同?

python - 如何将文件上传到 S3 并使用 boto3 将其公开?

ruby - 有没有办法创建 HIT,但延迟其对 Mechanical Turkers 的可用性?

java - Amazon Turk 命令行工具 : Invalid Configuration for Port error

java - Mechanical Turk 拒绝 POST 请求

php - osticket,通过 REST API 创建票证

python : open csv files from a list and convert them into xls

Python模拟全局变量

amazon-web-services - 无法使用 boto3 访问 SQS 消息属性

python - boto3 定价客户端的区域名称和位置之间的映射