【问题标题】:Strange failure to make a HIT for Amazon Mechanical Turk with some URLs?使用某些 URL 为 Amazon Mechanical Turk 制作 HIT 的奇怪失败?
【发布时间】:2013-05-23 15:45:15
【问题描述】:

我试图使用 boto 在 Amazon Mechanical Turk 的 HIT 请求中包含一个链接,但一直收到我的 XML 无效的错误消息。我逐渐将我的 html 缩减到最低限度,并且孤立地发现某些有效链接似乎无缘无故地失败了。任何具有 boto 或 aws 专业知识的人都可以帮助我解析原因吗?

我遵循了这两个指南:

这是我的例子:

from boto.mturk.connection import MTurkConnection
from boto.mturk.question import QuestionContent,Question,QuestionForm,Overview,AnswerSpecification,SelectionAnswer,FormattedContent,FreeTextAnswer
from config import *

HOST = 'mechanicalturk.sandbox.amazonaws.com'

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

title = 'HIT title'
description = ("HIT description.")
keywords = 'keywords'

s1 = """<![CDATA[<p>Here comes a link <a href='%s'>LINK</a></p>]]>""" % "http://www.example.com"
s2 = """<![CDATA[<p>Here comes a link <a href='%s'>LINK</a></p>]]>""" % "https://www.google.com/search?q=example&site=imghp&tbm=isch"

def makeahit(s):
    overview = Overview()
    overview.append_field('Title', 'HIT title itself')
    overview.append_field('FormattedContent',s)

    qc = QuestionContent()
    qc.append_field('Title','The title')

    fta = FreeTextAnswer()

    q = Question(identifier="URL",
                 content=qc,
                 answer_spec=AnswerSpecification(fta))

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

    mtc.create_hit(questions=question_form,
                   max_assignments=1,
                   title=title,
                   description=description,
                   keywords=keywords,
                   duration = 30,
                   reward=0.05)

makeahit(s1) # SUCCESS!
makeahit(s2) # FAIL?
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 25, in makeahit
  File "/usr/local/lib/python2.7/dist-packages/boto/mturk/connection.py", line 263, in create_hit
    return self._process_request('CreateHIT', params, [('HIT', HIT)])
  File "/usr/local/lib/python2.7/dist-packages/boto/mturk/connection.py", line 821, in _process_request
    return self._process_response(response, marker_elems)
  File "/usr/local/lib/python2.7/dist-packages/boto/mturk/connection.py", line 836, in _process_response
    raise MTurkRequestError(response.status, response.reason, body)
boto.mturk.connection.MTurkRequestError: MTurkRequestError: 200 OK
<?xml version="1.0"?>
<CreateHITResponse><OperationRequest><RequestId>19548ab5-034b-49ec-86b2-9e499a3c9a79</RequestId></OperationRequest><HIT><Request><IsValid>False</IsValid><Errors><Error><Code>AWS.MechanicalTurk.XHTMLParseError</Code><Message>There was an error parsing the XHTML data in your request.  Please make sure the data is well-formed and validates against the appropriate schema. Details: The reference to entity "site" must end with the ';' delimiter. Invalid content: &lt;FormattedContent&gt;&lt;![CDATA[&lt;p&gt;Here comes a link &lt;a href='https://www.google.com/search?q=example&amp;site=imghp&amp;tbm=isch'&gt;LINK&lt;/a&gt;&lt;/p&gt;]]&gt;&lt;/FormattedContent&gt; (1369323038698 s)</Message></Error></Errors></Request></HIT></CreateHITResponse>

知道为什么 s2 失败,但是当两个都是有效链接时 s1 成功?两个链接内容都有效:

带有查询字符串的东西? HTTPS?

更新

我要做一些测试,但现在我的候选假设是:

  1. HTTPS 不工作(所以,我会看看是否可以让另一个 https 链接工作)
  2. 带有参数的 URL 不起作用(所以,我会看看是否可以让另一个带有参数的 url 起作用)
  3. Google 不允许以这种方式发布其搜索? (如果 1 和 2 失败!)

【问题讨论】:

  • 你需要xml转义url吗?
  • 也许我错了,但我认为这就是 CDATA 所做的。这不正确吗?
  • 应该是真的,但觉得值得一试。
  • 你找到答案了吗?
  • 不,但我还没有追求我的更新想法。

标签: python amazon-web-services boto mechanicalturk


【解决方案1】:

您需要在 url 中转义 & 符号,即 &amp;amp; => &amp;amp;

在s2结束时,使用

q=example&amp;site=imghp&amp;tbm=isch

而不是

q=example&site=imghp&tbm=isch

【讨论】:

  • 安培通常是“%26”,对吧?但是 URL 中不允许 & 吗?当输入到我的 url 栏中时,该 URL 实际上可以使用 &。这就是谷歌原生查询的方式,看。你是说这是亚马逊的限制,还是我应该注意的其他事情?
  • 这是 XML 转义,这与您在 URL 中需要的转义不同。 URL 中允许使用 &,但亚马逊正在读取的文件是 XML,因此当它看到“&”时,它认为它是一个特殊字符的开头。
  • 这是一个有用的讨论:stackoverflow.com/questions/1091945/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多