2

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

Only HITs in reviewable state can be deleted.

But using the command line interface it seems to be possible: https://docs.aws.amazon.com/AWSMechTurk/latest/AWSMturkCLT/CLTReference_DeleteHITsCommand.html

My question is, can I somehow accomplish the command line behaviour of deleting not reviewable HITs using boto3 client?

1 Answer 1

13

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')
1
  • ahh so you need to update expiration AND ALSO delete it. That's the point I was missing. Thanks.
    – Gadam
    Commented Dec 8, 2020 at 1:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.