【问题标题】:Error message when submitting HIT to Amazon Mechanical Turk向 Amazon Mechanical Turk 提​​交 HIT 时出现错误消息
【发布时间】:2017-04-30 17:39:33
【问题描述】:

我在向 Amazon Mechanical Turk 沙盒提交 HIT 时遇到问题。

我正在使用以下代码提交 HIT:

external_content = """"
<ExternalQuestion xmlns="http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2006-07-14/ExternalQuestion.xsd">
  <ExternalURL>https://MY_HOST_GOES_HERE/</ExternalURL>
  <FrameHeight>400</FrameHeight>
</ExternalQuestion>
"""

import boto3

import os

region_name = 'us-east-1'

aws_access_key_id = 'MYKEY'
aws_secret_access_key = 'MYSECRETKEY'

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

# This will return $10,000.00 in the MTurk Developer Sandbox
print(client.get_account_balance()['AvailableBalance'])


response = client.create_hit(Question=external_content,
                             LifetimeInSeconds=60 * 60 * 24,
                             Title="Answer a simple question",
                             Description="Help research a topic",
                             Keywords="question, answer, research",
                             AssignmentDurationInSeconds=120,
                             Reward='0.05')

# The response included several helpful fields
hit_group_id = response['HIT']['HITGroupId']
hit_id = response['HIT']['HITId']

# Let's construct a URL to access the HIT
sb_path = "https://workersandbox.mturk.com/mturk/preview?groupId={}"
hit_url = sb_path.format(hit_group_id)

print(hit_url)

我得到的错误信息是:

botocore.exceptions.ClientError: An error occurred (ParameterValidationError) when calling the CreateHIT operation: There was an error parsing the XML question or answer data in your request.  Please make sure the data is well-formed and validates against the appropriate schema. Details: Content is not allowed in prolog. (1493572622889 s)

这可能是什么原因? xml 与位于亚马逊服务器上的 xml 架构完全一致。

外部主机返回的html是:

<!DOCTYPE html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'/>
<script src='https://s3.amazonaws.com/mturk-public/externalHIT_v1.js' type='text/javascript'></script>
</head>
<body>
<!-- HTML to handle creating the HIT form -->
<form name='mturk_form' method='post' id='mturk_form' action='https://workersandbox.mturk.com/mturk/externalSubmit'>
<input type='hidden' value='' name='assignmentId' id='assignmentId'/>
<!-- This is where you define your question(s) --> 
<h1>Please name the company that created the iPhone</h1>
<p><textarea name='answer' rows=3 cols=80></textarea></p>
<!-- HTML to handle submitting the HIT -->
<p><input type='submit' id='submitButton' value='Submit' /></p></form>
<script language='Javascript'>turkSetAssignmentID();</script>
</body>
</html>

谢谢

【问题讨论】:

    标签: python amazon boto3 mechanicalturk


    【解决方案1】:

    此消息“详细信息:序言中不允许内容。”是线索。事实证明,这就是说你不能在预期的地方拥有内容。当垃圾字符(想想智能引号或不可打印的 ASCII 值)出现在其中时,通常会发生这种情况。这些对于诊断来说可能是一个真正的痛苦。

    在您的情况下,调试起来稍微容易一些,但同样令人沮丧。看看这一行:

    external_content = """"
    

    事实证明,Python 只需要三个引号 (""") 来确认多行字符串定义。因此,您的第四个 " 实际上是作为 XML 的一部分呈现的。将该行更改为:

    external_content = """
    

    你是金子。我刚刚测试过它并且它有效。对所有的挫折感到抱歉,但希望这能解除你的阻碍。周日快乐!

    【讨论】:

    • 哈哈哈,你救了我的命!非常感谢!
    猜你喜欢
    • 1970-01-01
    • 2015-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多