簡體   English   中英

使用Boto發送針對MTurk命中的SQS通知

[英]Using Boto to send SQS notifications for an MTurk hit

我正在嘗試為使用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."

您應該在SQS的AWS控制台上進入自己的隊列,並添加新權限:

效果:允許

校長:arn:aws:iam :: 755651556756:user / MTurk-SQS

動作:SendMessage

稍后,您應該使用首選通知和隊列的URL構建HITType。

這樣,當您在mturk上創建HIT請求時,Amazon Mechanical Turk的唯一有效用戶“ MTurk-SQS”會將通知消息從mturk requester.sandbox帳戶發送到SQS隊列。

您可能需要從MTurkR的Notifications中查看這些步驟。

如果您仍在為此苦苦掙扎,則需要在SQS中設置一些權限,以允許MTurk向其發送消息。 它們在這里描述:在這里輸入鏈接描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM