如何使用Boto3客户端删除仍可用的HIT [英] How to delete still available HITs using boto3 client
问题描述
我为工人提供了一些已发布的HIT.现在,我想删除它们,尽管它们还没有被工人完成.根据此文档,不可能:
I have some published HITs available to workers. Now I want to delete them although they haven't been finished by the workers. According to this documentation, it is not possible: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/mturk.html#MTurk.Client.delete_hit
只有处于可审核状态的HIT才能删除.
Only HITs in reviewable state can be deleted.
但是似乎可以使用命令行界面: https://docs.aws.amazon.com/AWSMechTurk/latest/AWSMturkCLT/CLTReference_DeleteHITsCommand.html
But using the command line interface it seems to be possible: https://docs.aws.amazon.com/AWSMechTurk/latest/AWSMturkCLT/CLTReference_DeleteHITsCommand.html
我的问题是,我可以使用boto3客户端以某种方式完成删除不可审查的HIT的命令行行为吗?
My question is, can I somehow accomplish the command line behaviour of deleting not reviewable HITs using boto3 client?
推荐答案
部分解决方案是将可分配"的HIT设置为立即失效.我使用以下脚本清理Mechanical Turk沙箱:
The partial solution is to set an 'Assignable' HIT to expire immediately. I use this script for cleaning up the Mechanical Turk Sandbox:
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')
这篇关于如何使用Boto3客户端删除仍可用的HIT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!