Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating mTurk HIT from Layout with parameters using boto and python

I am attempting to utilize boto to generate a HIT in mechanical turk. The goal is to use a common layout that is already generated on my mTurk account, and pass it urls of images to iteratively create HITs.

The issue is that even with correctly naming the parameter if for the image urls boto is not successful. My example code to create the hit is:

from boto.mturk.connection import MTurkConnection
from boto.s3.connection import S3Connection
from boto.mturk.layoutparam import LayoutParameter
from boto.s3.key import Key
import datetime

mtc = MTurkConnection(aws_access_key_id=AWSKEY,
                  aws_secret_access_key=AWSSKEY,
                  host=HOST)

#Define the layout ID to use and url to the image being used (bucket and serial defined in another place
LAYOUTID = '30W9SLHWRYCURO27D44916CUTGKDS2'
S3URL = LayoutParameter('image_url','https://s3.amazonaws.com/'+BUCKET_NAME+'/'+SERIAL)
REWARD = 0.05

#Call create_hit to generate the HIT
hit_result = mtc.create_hit(hit_layout=LAYOUTID,layout_params=S3URL,  keywords=keywords_list, reward=REWARD,
                            duration=datetime.timedelta(7),max_assignments=1)

This generates the error Your request is missing required parameters. Required parameters include HITLayoutParameter. You have not provided all required HITLayout parameters. Missing parameter names: image_url

And just to make sure, my layout ID has the correct parameter names, when I check mTurk I see (can't post a screengrab):

Layout ID: 30W9SLHWRYCURO27D44916CUTGKDS2 Parameters: image_url

Are there any tricks to using LayoutParameter? Or am I using create_hit in the wrong way?

like image 555
fridrik.larusson Avatar asked Mar 23 '15 03:03

fridrik.larusson


1 Answers

Hi there I know it's a little too late for an answer but here's what you need to do. Package the layout parameters in a LayoutParameters class after putting them in the LayoutParameter class. eg.

......
from boto.mturk.layoutparam import LayoutParameter
from boto.mturk.layoutparam import LayoutParameters
........

S3URL = LayoutParameter('image_url','https://s3.amazonaws.com/'+BUCKET_NAME+'/'+SERIAL)

# put the layout parameter in a list/tuple and pass it to LayoutParameters
params = LayoutParameters([S3URL])

hit_result = mtc.create_hit(hit_layout=LAYOUTID,layout_params=params,  keywords=keywords_list, reward=REWARD,
                            duration=datetime.timedelta(7),max_assignments=1)
like image 81
michaelmwangi Avatar answered Oct 29 '22 11:10

michaelmwangi