如何向boto3提交机械突厥外部问题

如何向boto3提交机械突厥外部问题,boto3,Boto3,我试图用boto3编程创建一个关于mechanical turk的问题,但我似乎做错了什么,因为create\u hit所需的ExternalQuestion数据结构似乎丢失了 我试着创造出这样的热门作品: import boto3 #... client = boto3.client( 'mturk', endpoint_url=endpoint_url, region_name=region_name, aws_access_key_id=aws_acce

我试图用boto3编程创建一个关于mechanical turk的问题,但我似乎做错了什么,因为
create\u hit
所需的
ExternalQuestion
数据结构似乎丢失了

我试着创造出这样的热门作品:

import boto3

#...

client = boto3.client(
    'mturk',
    endpoint_url=endpoint_url,
    region_name=region_name,
    aws_access_key_id=aws_access_key_id,
    aws_secret_access_key=aws_secret_access_key,
)

question = ExternalQuestion(external_url=question_target, frame_height=800)

response = client.create_hit(
        MaxAssignments=10,
        Title='Test',
        Description='This is a test of ExternalQuestion',
        Question=question,
        AssignmentDurationInSeconds=60,
        LifetimeInSeconds=24 * 60 * 60,
        Reward=0.01)
哪个失败了:

Traceback (most recent call last):
  File "createTask.py", line 21, in <module>
    question = ExternalQuestion(external_url=question_target, frame_height=800)
NameError: name 'ExternalQuestion' is not defined
回溯(最近一次呼叫最后一次):
文件“createTask.py”,第21行,在
问题=外部问题(外部url=问题目标,框架高度=800)
NameError:未定义名称“ExternalQuestion”

非常感谢您对如何进行的任何建议。

这是我的生产代码中的一个直接片段。我打开了一个XML文件,您可以从请求者站点获取一个模板,然后将其编辑为包含您自己的javascript和html。我将在下面附上一个样品

Python

import boto3
region_name = 'us-east-1'
aws_access_key_id = '*********************'
aws_secret_access_key = '*********************'
endpoint_url = 'https://mturk-requester-sandbox.us-east-1.amazonaws.com'

# Uncomment this line to use in production
#endpoint_url = 'https://mturk-requester.us-east-1.amazonaws.com'
client = boto3.client(
    'mturk',
    endpoint_url=endpoint_url,
    region_name=region_name,
    aws_access_key_id=aws_access_key_id,
    aws_secret_access_key=aws_secret_access_key,
)
questionSampleFile = open("K:/" + str(somefile) + ".xml", "r")
questionSample = questionSampleFile.read()

localRequirements = [{
    'QualificationTypeId': '00000000000000000071',
    'Comparator': 'NotIn',
    'LocaleValues': [{
     'Country': 'WF'
   }],
   'RequiredToPreview': True
    }]
xReward = '0.25'
# Create the HIT 
response = client.create_hit(
    MaxAssignments = 1,
    #AutoApprovalDelayInSeconds = 259200,
    #3 days for lifetime
    LifetimeInSeconds = 172800,
    #1 hour to finish the assignment
    AssignmentDurationInSeconds = 5400,
    Reward = xReward,
    Title = 'Enter Missing Data',
    Keywords = 'data entry, typing, inspection',
    Description = 'Edit and Add Data from PDF',
    Question = questionSample,
    QualificationRequirements = localRequirements
)
XML

<HTMLQuestion xmlns="http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2011-11-11/HTMLQuestion.xsd">
  <HTMLContent><![CDATA[

]]>
  </HTMLContent>
  <FrameHeight>900</FrameHeight>
</HTMLQuestion>

900

如果您仍然安装了较旧版本的
boto
,最简单的方法是使用
ExternalQuestion
get\u as\u xml()
方法:

导入boto3
从boto.mturk.question导入外部问题
mturk=boto3.client(
“mturk”,
端点https://mturk-requester-sandbox.us-east-1.amazonaws.com',
地区名称='us-east-1',
aws_access_key_id='your_access_key',
aws_secret_access_key='your_secret_key',
)
问题=外部问题(“https://example.com/mypage.html“,框架高度=600)
新建命中率=mturk.create命中率(
Title='回答一个简单的问题',
Description='Help research a topic',
关键词=“问题、答案、研究”,
奖励='0.15',
MaxAssignments=1,
LifetimeInSeconds=172800,
AssignmentDurationInSeconds=600,
AutoApprovalDelayInSeconds=14400,

Question=Question.get_as_xml(),#如果您正在寻找与classic boto中相同的类接口,这里有一个独立的代码片段来模拟它:

类外部问题:
"""
用于构造外部问题的对象。
"""
架构\ url=”http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2006-07-14/ExternalQuestion.xsd"
模板='%%(外部url)s%%(帧高度)s'%vars()
定义初始(自身、外部url、帧高度):
self.external\u url=外部\u url
self.frame\u height=frame\u height
def get_as_参数(self,label='ExternalQuestion'):
返回{label:self.get_as_xml()}
def get_as_xml(self):
返回self.template%vars(self)

ExternalQuestion是一个数据结构,而不是函数。它应该在XML文件中创建,然后在Python中使用
open()
命令并将
file.read()
传递给问题参数参见示例代码