3

我试图在 Amazon Mechanical Turk 的 HIT 请求中包含一个链接,使用 boto,并不断收到我的 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. 谷歌不允许它的搜索以这种方式发布?(如果 1 和 2 失败!)
4

1 回答 1

2

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

在 s2 结束时,使用

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

代替

q=example&site=imghp&tbm=isch
于 2013-08-14T15:03:57.390 回答