I'm trying to set up SQS notifications for an MTurk HIT created using Boto. I'm able to create the HIT type, create a HIT with that type, create an SQS queue, and write to and read from the queue. I've also written the command that (I thought) would set notifications for the given HIT type. But no notifications are sent.
Any idea what's going on?
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."