RDFLib / rdflib

RDFLib is a Python library for working with RDF, a simple yet powerful language for representing information.
https://rdflib.readthedocs.org
BSD 3-Clause "New" or "Revised" License
2.13k stars 549 forks source link

SPARQLStore fails to load data from DBPedia #393

Closed olberger closed 7 years ago

olberger commented 10 years ago

The following code issues an errror :

import urllib2
from rdflib import Graph, URIRef
from rdflib.plugins.stores.sparqlstore import SPARQLStore

if 1:
    handler = urllib2.HTTPHandler(debuglevel=1)
    opener = urllib2.build_opener(handler)
    urllib2.install_opener(opener)

store = SPARQLStore("http://dbpedia.org/sparql",
                    context_aware=False)
graph = Graph(store)

for p, o in graph.predicate_objects(URIRef('http://dbpedia.org/resource/Teheran_43')):
    continue
send: 'GET /sparql?query=%0ASELECT+%3Fp+%3Fo+WHERE+%7B+%3Chttp%3A%2F%2Fdbpedia.org%2Fresource%2FTeheran_43%3E+%3Fp+%3Fo+%7D HTTP/1.1\r\nAccept-Encoding: identity\r\nHost: dbpedia.org\r\nConnection: close\r\nAccept: application/sparql-results+xml\r\nUser-Agent: sparqlwrapper 1.5.2 (http://sparql-wrapper.sourceforge.net/)\r\n\r\n'
reply: 'HTTP/1.1 200 OK\r\n'
header: Date: Wed, 14 May 2014 11:45:17 GMT
header: Content-Type: application/sparql-results+xml; charset=UTF-8
header: Content-Length: 24350
header: Connection: close
header: Server: Virtuoso/07.10.3209 (Linux) i686-generic-linux-glibc212-64  VDB
header: Accept-Ranges: bytes
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/olivier/git/github.com/gjhiggins/RDFAlchemy/rdfalchemy/samples/bug.py", line 14, in <module>
    for p, o in graph.predicate_objects(URIRef('http://dbpedia.org/resource/Teheran_43')):
  File "/usr/lib/python2.7/dist-packages/rdflib/graph.py", line 647, in predicate_objects
    for s, p, o in self.triples((subject, None, None)):
  File "/usr/lib/python2.7/dist-packages/rdflib/graph.py", line 426, in triples
    for (s, p, o), cg in self.__store.triples((s, p, o), context=self):
  File "/usr/lib/python2.7/dist-packages/rdflib/plugins/stores/sparqlstore.py", line 377, in triples
    for rt, vars in TraverseSPARQLResultDOM(doc, asDictionary=True):
  File "/usr/lib/python2.7/dist-packages/rdflib/plugins/stores/sparqlstore.py", line 115, in TraverseSPARQLResultDOM
    term = CastToTerm(binding.findall('*')[0])
  File "/usr/lib/python2.7/dist-packages/rdflib/plugins/stores/sparqlstore.py", line 152, in CastToTerm
    "{http://www.w3.org/XML/1998/namespace}lang"])
  File "/usr/lib/python2.7/dist-packages/rdflib/term.py", line 573, in __new__
    _value, _datatype = _castPythonToLiteral(lexical_or_value)
  File "/usr/lib/python2.7/dist-packages/rdflib/term.py", line 1388, in _castPythonToLiteral
    if isinstance(obj, pType):
TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and types

Hope this helps.

Thanks in advance.

chrysn commented 7 years ago

This appears to be fixed before or in 4.2.1.

joernhees commented 7 years ago

thanks for letting us know... closing this, please open new issue in case this re-appears.

(and sorry for no reply to this ages ago)