Debugging windows7上的RDflib结果打印错误

Debugging windows7上的RDflib结果打印错误,debugging,python-2.7,runtime-error,sparql,sparqlwrapper,Debugging,Python 2.7,Runtime Error,Sparql,Sparqlwrapper,我使用SPARQLWrapper创建SPARQL查询,但我不知道如何调试以下错误消息: Warning (from warnings module): File "D:\Python27\lib\site-packages\sparqlwrapper-1.5.2-py2.7.egg\SPARQLWrapper\Wrapper.py", line 550 RuntimeWarning: unknown response content type, returning raw response.

我使用SPARQLWrapper创建SPARQL查询,但我不知道如何调试以下错误消息:

Warning (from warnings module):
  File "D:\Python27\lib\site-packages\sparqlwrapper-1.5.2-py2.7.egg\SPARQLWrapper\Wrapper.py", line 550
RuntimeWarning: unknown response content type, returning raw response...

Traceback (most recent call last):
  File "D:\Python27\testwrapper.py", line 31, in <module>
    if (len(results["results"]["bindings"]) == 0):
AttributeError: addinfourl instance has no attribute '__getitem__'
警告(来自警告模块):
文件“D:\Python27\lib\site packages\sparqlwrapper-1.5.2-py2.7.egg\sparqlwrapper\Wrapper.py”,第550行
RuntimeWarning:未知响应内容类型,正在返回原始响应。。。
回溯(最近一次呼叫最后一次):
文件“D:\Python27\testwrapper.py”,第31行,在
如果(len(results[“results”][“bindings”])==0):
AttributeError:AddInfo实例没有属性“\uuu getitem\uuu”
这是我的代码:

from SPARQLWrapper import SPARQLWrapper,JSON
sparql = SPARQLWrapper('http://thedatahub.org/dataset/semanticquran');

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 DISTINCT  ?wordText ?pos
WHERE
 { ?wordPart rdf:type qvoc:LexicalItem .
    ?wordPart gold:Root "smw" .
    ?wordPart dcterms:isPartOf ?word .
    ?wordPart gold:PartOfSpeechProperty ?pos .
    ?word rdf:type qvoc:Word .
    ?word skos:prefLabel ?wordText
  }
"""

sparql.setQuery(queryString)
sparql.setReturnFormat(JSON)
results = sparql.query().convert()
if (len(results["results"]["bindings"]) == 0):
  print "No results found."
else:
  for result in results["results"]["bindings"]:
     print result["wordText"]["value"]
从SPARQLWrapper导入SPARQLWrapper,JSON
sparql=SPARQLWrapper('http://thedatahub.org/dataset/semanticquran');
queryString=“”
前缀dc:
前缀foaf:
前缀ar:
前缀dcterms:
前缀rdfs:
前缀owl:
前缀xsd:
前缀lexvo:
前缀rdf:
前缀黄金:
前缀skos:
前缀qvoc:
选择不同的文字位置
哪里
{?wordPart rdf:type qvoc:LexicalItem。
?wordPart gold:词根“smw”。
?wordPart dcterms:isPartOf?word。
?wordPart gold:PartOfSpeechProperty?位置。
?单词rdf:类型qvoc:单词。
?word skos:prefLabel?word文本
}
"""
setQuery(queryString)
setReturnFormat(JSON)
结果=sparql.query().convert()
如果(len(results[“results”][“bindings”])==0):
打印“未找到结果”
其他:
对于结果[“结果”][“绑定”]:
打印结果[“wordText”][“value”]
有任何帮助吗?

不是JSON,因此
setReturnFormat
调用未按预期工作:

根据返回格式对返回值进行编码:

  • 对于XML,返回一个DOM top元素
  • 对于JSON,simplejson转换将返回一个字典
  • 对于RDF/XML,该值通过RDFLib转换为图形实例
在所有其他情况下,输入只是返回