Creating mTurk HIT from Layout with parameters using boto and python

不羁岁月 提交于 2019-12-13 13:11:14

问题


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?


回答1:


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)


来源:https://stackoverflow.com/questions/29202837/creating-mturk-hit-from-layout-with-parameters-using-boto-and-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!