Warm tip: This article is reproduced from serverfault.com, please click

python-从Sandbox HIT检索结果返回空的xml字典

(python - Retrieving results from Sandbox HIT returns empty xml dictionary)

发布于 2020-08-31 17:49:53

我正在尝试在Amazon Mechanical Turk上创建一个实验。我已经从这个SO问题中借用了代码它运行无错误,但返回一个空数组。代码是:

import boto3
import xmltodict

MTURK_SANDBOX = 'https://mturk-requester-sandbox.us-east-1.amazonaws.com'
MTURK_PROD = 'https://mturk-requester.us-east-1.amazonaws.com'
mturk = boto3.client('mturk',
   aws_access_key_id = "key",
   aws_secret_access_key = "secret_key",
   region_name='us-east-1',
   endpoint_url = MTURK_SANDBOX
)

# Read in the questions.xml file saved in the same directory
question = open(file='questions.xml',mode='r', encoding='utf-8').read()
new_hit = mturk.create_hit(
    Title = 'Map the following question to the paragraph/content where the answer to the question may lie.',
    Description = 'Please review the following content to figure out where the answer to the posted question may reside',
    Keywords = 'images, quick, labeling',
    Reward = '0.00',
    MaxAssignments = 1,
    LifetimeInSeconds = 1728,
    AssignmentDurationInSeconds = 600,
    AutoApprovalDelayInSeconds = 14400,
    Question = question,
    AssignmentReviewPolicy={
        'PolicyName':'ScoreMyKnownAnswers/2011-09-01',
        'Parameters':[
            {'Key':'AnswerKey', 'MapEntries':[{'Key': 'question_1', 'Values':['yes']}]},
            {'Key': 'ApproveIfKnownAnswerScoreIsAtLeast', 'Values':['1']},
            {'Key': 'RejectIfKnownAnswerScoreIsLessThan', 'Values':['1']},{'Key': 'RejectReason', 'Values':['Sorry, we could not approve your submission as you did not correctly identify the image containing the Flamingo.']},
            {'Key': 'ExtendIfKnownAnswerScoreIsLessThan','Values':['1']}
    ]}
)

print("A new HIT has been created. You can preview it here:")
print(new_hit['HIT']['HITGroupId'])
print("https://workersandbox.mturk.com/mturk/preview?groupId=" + str(new_hit['HIT']['HITGroupId']))

# Retrive results
# Use the hit_id previously created
hit_id = new_hit['HIT']['HITId']
# We are only publishing this task to one Worker
# So we will get back an array with one item if it has been completed
worker_results = mturk.list_assignments_for_hit(HITId=hit_id, AssignmentStatuses=['Submitted'])
print(worker_results)

其中questions.xml的样子:

<HTMLQuestion xmlns="http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2011-11-11/HTMLQuestion.xsd">
<HTMLContent><![CDATA[
<!-- YOUR HTML BEGINS -->
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'/>
<script type='text/javascript' src='https://s3.amazonaws.com/mturk-public/externalHIT_v1.js'></script>
</head>
<body>
<form name='mturk_form' method='post' id='mturk_form' action='https://www.mturk.com/mturk/externalSubmit'><input type='hidden' value='' name='assignmentId' id='assignmentId'/>
<h2>Is this Tweet happy, angry, excited, scared, annoyed or upset? Type in one word to describe the main emotion in the message. If it is unclear, type in "unclear".</h2>
<h3> Tweet: "I am really looking forward to the next Seahawks game!"</h3>
<div>
  <input type='text' name='reported_emotion' placeholder='Type in your answer here'>
</div>
<p><input type='submit' id='submitButton' value='Submit' /></p></form>
<script language='Javascript'>turkSetAssignmentID();</script>
</body></html>
<!-- YOUR HTML ENDS -->
]]>
</HTMLContent>
<FrameHeight>600</FrameHeight>
</HTMLQuestion>

然后我完成和。使用我创建的MTurk辅助帐户接受HIT。我得到的xml字典worker_results是:

{'NumResults': 0, 'Assignments': [], 'ResponseMetadata': {'RequestId': '29d88641-ce06-4734-9fd4-b8ac8cb02d03', 'HTTPStatusCode': 200, 'HTTPHeaders': {'x-amzn-requestid': '29d88641-ce06-4734-9fd4-b8ac8cb02d03', 'content-type': 'application/x-amz-json-1.1', 'content-length': '33', 'date': 'Mon, 31 Aug 2020 17:37:51 GMT'}, 'RetryAttempts': 0}}

这不应该至少在前两个条目中显示值吗?

Questioner
Adam_G
Viewed
0
Trenton 2020-12-02 06:37:47

你的代码正在运行。Assignments工作人员接受并提交你的HIT之前,字段将保持空白。