使用boto和python从带有参数的布局创建mTurk命中

2024-10-02 12:29:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图利用boto在机械土耳其人中制造命中。目标是使用已经在mTurk帐户上生成的一个公共布局,并将图像的url传递给它,以迭代方式创建点击。在

问题是,即使正确命名了参数if对于图像url,boto也不成功。创建hit的示例代码是:

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)

这会产生错误 您的请求缺少必需的参数。必需参数包括HITLayoutParameter。您尚未提供所有必需的HITLayout参数。缺少参数名:image_url

为了确保我的layout ID有正确的参数名,当我检查mTurk时,我看到(不能发布屏幕抓图):

Layout ID: 30W9SLHWRYCURO27D44916CUTGKDS2 Parameters: image_url

使用LayoutParameter有什么窍门吗?还是我用create_hit的方式不对?在


Tags: thetokeyfromimageimportidurl
1条回答
网友
1楼 · 发布于 2024-10-02 12:29:20

嗨,我知道现在回答有点晚了,但你需要做的是。将布局参数放入LayoutParameters类后,将其打包到LayoutParameters类中。 例如

......
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)

相关问题 更多 >

    热门问题