amazon-web-services - 使用带 boto3 的 ExternalQuestion 在 Amazon Mechnical Turk 上创建命中
问题描述
这个问题以前有人问过,但答案只包含了一点点答案。
问题:
如何ExternalQuestion
使用 boto3 api 创建命中?
常见问题
也许 externalQuestions 尚未定义,因为它不是 boto3 的一部分:
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
或者,如果您已设法创建ExternalQuestion
数据模型,则create_hit
可能仍会返回以下错误,说明ExternalQuestion
数据类型错误。
botocore.exceptions.ParamValidationError: Parameter validation failed:
Invalid type for parameter Question, value: <mturk.utils.ExternalQuestion instance at 0x70b2560>, type: <type 'instance'>, valid types: <type 'basestring'>
解决方案
第一步:创建正确的ExternalQuestion
数据模型。
这个答案显示了如何做这第一部分。
class ExternalQuestion:
"""
An object for constructing an External Question.
"""
schema_url = "http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2006-07-14/ExternalQuestion.xsd"
template = '<ExternalQuestion xmlns="%(schema_url)s"><ExternalURL>%%(external_url)s</ExternalURL><FrameHeight>%%(frame_height)s</FrameHeight></ExternalQuestion>' % vars()
def __init__(self, external_url, frame_height):
self.external_url = external_url
self.frame_height = frame_height
def get_as_params(self, label='ExternalQuestion'):
return {label: self.get_as_xml()}
def get_as_xml(self):
return self.template % vars(self)
然后,我们创建一个ExternalQuestion
如下的实例:
external_question = ExternalQuestion(
external_url='www.google.com',
frame_height=2200
)
步骤 2. 创建命中
现在我们有了命中,我们可以使用create_hit
or with提交它create_hit_with_with_type
。ExternalQuestion
但棘手的部分是必须与实例一起提供的 Question 参数,它需要是一个基本字符串。文件对此很模糊。我只是因为这个答案才想出来的。
client.create_hit_with_hit_type(
Question = external_question.get_as_xml()
# all the other required arguments
)
推荐阅读
- c# - 根据不同的变量放置对象
- css - 如何对齐图标?
- javascript - 私有 Deno 包注册表
- python - 尝试网络抓取时我的代码不打印
- azure-data-factory - 数据流活动 Azure 数据工厂中的并发文件处理
- javascript - 下拉菜单 - 在重新加载时保存选择
- python - 从冻结层获取输出张量
- c - 当我不使用引号时,argc 究竟是如何工作的?
- php - 使用被 gmail 阻止的 mailgun smtp 的 php 邮件;错误 RFC 5322
- python - 如何在 vscode windows 10 上打开 graphviz(dot) 文件