微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决从Sandbox HIT检索结果返回空的xml字典

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

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',{'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。我以worker_results得到的xml字典是:

{'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}}

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

解决方法

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。