2017-04-30 220 views
0

我在提交HIT到Amazon Mechanical Turk沙箱時遇到問題。提交HIT到亞馬遜Mechanical Turk時出現錯誤信息

我用下面的代碼提交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> 

謝謝

回答

1

此消息 「詳細信息:內容是不是在序言中不允許的。」是線索。事實證明,這就是說你不能在預期之外擁有內容。這是通常發生在垃圾字符(認爲是智能引號或不可打印的ASCII值)的地方。這些可以成爲診斷的真正痛處。

就你而言,調試有點容易,但仍然令人沮喪。看看這個行:

external_content = """" 

事實證明,Python中只需要三個引號(「」「)實際上呈現爲XML的一部分,以確認一個多行字符串定義。因此您的第四位。」。將該行更改爲:

external_content = """ 

而你是金。我只是測試它,它的工作原理。對不起所有的沮喪,但希望這可以解除您的阻礙。快樂星期天!

+0

哈哈哈,你救了我的一天!非常感謝! –

相關問題