【问题标题】:HTTP Error 414 with query to DBPedia endpoint using SPARQLwrapper使用 SPARQLwrapper 查询 DBPedia 端点的 HTTP 错误 414
【发布时间】:2013-07-03 18:08:18
【问题描述】:

我创建了一个在 DBpedia SPARQL 端点上执行 SPARQL 查询的函数。这个函数接受一个包含 15 个元素的数组,每次它从数组中替换一个元素到查询中,然后执行它以获取结果。问题是它需要前 9 个元素然后引发此错误:

results = sparql.query().convert()
  File "build/bdist.linux-i686/egg/SPARQLWrapper/Wrapper.py", line 390, in query
    return QueryResult(self._query())
  File "build/bdist.linux-i686/egg/SPARQLWrapper/Wrapper.py", line 369, in _query
    raise e
HTTPError: HTTP Error 414: Request-URI Too Large

我的查询如下:

sparql = SPARQLWrapper('http://mlode.nlp2rdf.org/sparql');
querystring="""
PREFIX  dc:<http://purl.org/dc/elements/1.1/>
PREFIX  foaf: <http://xmlns.com/foaf/0.1/>
PREFIX  olia-ar: <http://purl.org/olia/arabic_khoja.owl#>
PREFIX  dcterms: <http://purl.org/dc/terms/>
PREFIX  rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX  owl:  <http://www.w3.org/2002/07/owl#>
PREFIX  xsd:  <http://www.w3.org/2001/XMLSchema#>
PREFIX  lexvo: <http://lexvo.org/id/iso639-3/>
PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX  gold: <http://purl.org/linguistics/gold/>
PREFIX  skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX  qvoc: <http://www.nlp2rdf.org/quranvocab#>
SELECT  ?verseTextAr ?tafseer 
WHERE
  {
    ?verse a qvoc:Verse;
     qvoc:chapterIndex 26;
     qvoc:verseIndex  WORD;
     skos:prefLabel ?verseTextAr;
      qvoc:descByJalalayn ?tafseer.
  }
  """

【问题讨论】:

    标签: http python-2.7 sparql dbpedia sparqlwrapper


    【解决方案1】:

    414 错误意味着 SPARQLWrapper 正在尝试为查询执行 HTTP GET,但查询太大导致 DBPedia 服务器拒绝请求 URI。

    您需要将 SPARQLWrapper 改为 POST 查询,documentation 声明这是可能的,并且似乎应该使用 setMethod() 方法来配置它。

    【讨论】:

    • 我已经对其进行了编辑并尝试了“setMethod(POST)”,出现的结果比没有它的结果多,但它引发了另一个错误“HTTPError: HTTP Error 502: Bad Gateway”..你能帮帮我吗?
    • 502 是服务器端的错误,除了在他们的邮件列表中提问之外,您无能为力 - 请参阅wiki.dbpedia.org/Support
    • 如果我的回答对你有帮助,别忘了接受 - meta.stackexchange.com/a/5235/133890
    • 不幸的是,链接现在已经断开。
    • @Cleb 我已修复指向新文档位置的链接
    猜你喜欢
    • 2021-01-13
    • 1970-01-01
    • 2019-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-07
    • 1970-01-01
    相关资源
    最近更新 更多