【问题标题】:Using Boto to send SQS notifications for an MTurk hit使用 Boto 发送 MTurk 命中的 SQS 通知
【发布时间】:2015-09-21 05:39:11
【问题描述】:

我正在尝试为使用 Boto 创建的 MTurk HIT 设置 SQS 通知。我能够创建 HIT 类型,使用该类型创建 HIT,创建 SQS 队列,以及从队列中写入和读取。我还编写了(我认为)将为给定的 HIT 类型设置通知的命令。但没有发送通知。

知道发生了什么吗?

print "Debugging..."

import boto
import boto.sqs
from boto.mturk.connection import MTurkConnection
from boto.mturk.question import QuestionContent, Question, QuestionForm, \
    Overview, AnswerSpecification, SelectionAnswer, FormattedContent, \
    FreeTextAnswer
import uuid

ACCESS_ID = 'REDACTED'
SECRET_KEY = 'REDACTED'
HOST = 'mechanicalturk.sandbox.amazonaws.com'

mtc = MTurkConnection(aws_access_key_id=ACCESS_ID,
                      aws_secret_access_key=SECRET_KEY,
                      host=HOST)

print mtc.get_account_balance()

# --------------- DESIGN THE HIT -------------------

title = 'Give your opinion about a website ' + str(uuid.uuid4())
print title

description = ('Visit a website and give us your opinion about'
               ' the design and also some personal comments')
keywords = 'website, rating, opinions'

ratings = [
    ('Very Bad', '-2'),
    ('Bad', '-1'),
    ('Not bad', '0'),
    ('Good', '1'),
    ('Very Good', '1')
]

# ---------------  BUILD OVERVIEW -------------------

overview = Overview()
overview.append_field('Title', 'Give your opinion on this website')
overview.append(FormattedContent('hello'))

qc1 = QuestionContent()
qc1.append_field('Title', 'Your personal comments')

fta2 = FreeTextAnswer()

q = Question(identifier="comments",
             content=qc1,
             answer_spec=AnswerSpecification(fta2))

# --------------- BUILD THE QUESTION FORM -------------------

question_form = QuestionForm()
question_form.append(overview)
question_form.append(q)

# --------------- CREATE THE HIT -------------------

hit_type = mtc.register_hit_type(
    title,
    description,
    0.05,
    60*5,
    keywords=keywords,
    approval_delay=None,
    qual_req=None)[0]

print hit_type.HITTypeId

hit = mtc.create_hit(
    hit_type=hit_type.HITTypeId,
    questions=question_form,
    max_assignments=1,
    title=title,
    description=description,
    keywords=keywords,
    duration=60*5,
    reward=0.05)[0]

print hit
print dir(hit)
print hit.HITTypeId

sqs_connection = boto.sqs.connect_to_region(
    "us-west-2",
    aws_access_key_id=ACCESS_ID,
    aws_secret_access_key=SECRET_KEY)

# Set up Amazon Simple Queue Service.
queue_name = "wallace_queue"
queue = sqs_connection.create_queue(queue_name)
sqs_connection.add_permission(
    queue,
    "MTurkSendMessage",
    "755651556756",
    "SendMessage")

m = boto.sqs.message.Message()
m.set_body("hello world.")
queue.write(m)

rs = queue.get_messages()
for m in rs:
    msg = m.get_body()
    print "got message:"
    print msg
    assert msg == "hello world."

# set up queue notifications
qrl = "https://sqs.us-west-2.amazonaws.com/134127175127/" + queue_name
all_event_types = [
    "AssignmentAccepted",
    "AssignmentAbandoned",
    "AssignmentReturned",
    "AssignmentSubmitted",
    "HITReviewable",
    "HITExpired",
]
mtc.set_sqs_notification(
    hit.HITTypeId, qrl, event_types=all_event_types)

print "Done."

【问题讨论】:

    标签: python boto amazon-sqs mechanicalturk


    【解决方案1】:

    您应该在 SQS 的 AWS 控制台上进入您自己的队列并添加新权限:

    效果:允许

    委托人:arn:aws:iam::755651556756:user/MTurk-SQS

    操作:发送消息

    稍后,您应该使用您喜欢的通知和队列的 url 构建您的 HITType。

    这样,当您在 mturk 上创建 HIT 请求时,Amazon Mechanical Turk“MTurk-SQS”的唯一有效用户会将您的通知消息从您的 mturk requester.sandbox 帐户发送到您的 SQS 队列。

    您可能需要从MTurkR's Notifications 看到这些步骤。

    【讨论】:

      【解决方案2】:

      如果您仍在为此苦苦挣扎,您需要在 SQS 中设置一些权限,以允许 MTurk 向其发送消息。它们在这里被描述:enter link description here

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-02-03
        • 1970-01-01
        • 1970-01-01
        • 2012-07-16
        • 2015-05-26
        相关资源
        最近更新 更多