RDFLib / sparqlwrapper

A wrapper for a remote SPARQL endpoint
https://sparqlwrapper.readthedocs.io/
Other
520 stars 122 forks source link

SPARQL Wrapper returning empty results #95

Closed noorbakerally closed 6 years ago

noorbakerally commented 6 years ago

I have a query """CONSTRUCT { https://bistrotdepays.opendatasoft.com/id/theme/Sport%2C%20Loisirs ?p ?o . } WHERE { https://bistrotdepays.opendatasoft.com/id/tme/Sport%2C%20Loisirs ?p ?o . }""" and I'm using the SPARQLWrapper to query the sparql endpoint http://opensensingcity.emse.fr/sparql/bistro but returning an empty results. I'm executing the same query on that sparql endpoint using the YASGUI sparql client and I'm properly getting results. this appear to be a problem with the SPARQLWrapper

from SPARQLWrapper import SPARQLWrapper, JSON
from rdflib import Graph

query = """CONSTRUCT { <https://bistrotdepays.opendatasoft.com/id/theme/Sport%2C%20Loisirs> ?p ?o . } WHERE {  <https://bistrotdepays.opendatasoft.com/id/tme/Sport%2C%20Loisirs> ?p ?o . }"""

sparql = SPARQLWrapper("http://opensensingcity.emse.fr/sparql/bistro")
sparql.setQuery(query)
results = sparql.query()
print results.response.read()

which returns

<rdf:RDF
    xmlns:dct="http://purl.org/dc/terms/"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:skos="http://www.w3.org/2004/02/skos/core#"
    xmlns:dcat="http://www.w3.org/ns/dcat#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
    xmlns:foaf="http://xmlns.com/foaf/0.1/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#">
</rdf:RDF>
dayures commented 6 years ago

Maybe there is a typo in the CONSTRUCT query (tme instead of theme:

WHERE { https://bistrotdepays.opendatasoft.com/id/tme/Sport%2C%20Loisirs ?p ?o . } WHERE { https://bistrotdepays.opendatasoft.com/id/theme/Sport%2C%20Loisirs ?p ?o . }

Is that?

noorbakerally commented 6 years ago

sadly yes, i'm about to hit my head with the wall, sorry for this silly mistake & thanks

On Fri, Nov 24, 2017 at 1:43 PM, dayures notifications@github.com wrote:

Maybe there is a typo in the CONSTRUCT query (tme instead of theme:

WHERE { https://bistrotdepays.opendatasoft.com/id/tme/Sport%2C%20Loisirs ?p ?o . } WHERE { https://bistrotdepays.opendatasoft.com/id/theme/Sport%2C%20Loisirs ?p ?o . }

Is that?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/RDFLib/sparqlwrapper/issues/95#issuecomment-346820765, or mute the thread https://github.com/notifications/unsubscribe-auth/ABHg-leOpvgNa9qBGRfJyfYFwndAnwEfks5s5rntgaJpZM4QptBc .

dayures commented 6 years ago

No problem! Pair programming helps :)

noorbakerally commented 6 years ago

Oops, in fact, the query I put upwards correctly works (after the silly mistake) but the SPARQL below doesn't work with RDFlib, with the YasGui client, it does,

PREFIX dcat: <http://www.w3.org/ns/dcat#>
PREFIX data: <http://opensensingcity.emse.fr/LDPDesign/data/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX : <http://opensensingcity.emse.fr/LDPDesignVocabulary/>
CONSTRUCT { <https://bistrotdepays.opendatasoft.com/id/theme/Sport%2C%20Loisirs> ?p ?o . } WHERE {  <https://bistrotdepays.opendatasoft.com/id/theme/Sport%2C%20Loisirs> ?p ?o . }

When I uses this query, I get a connection reset problem:

    results = sparql.query()
  File "build/bdist.linux-x86_64/egg/SPARQLWrapper/Wrapper.py", line 567, in query
  File "build/bdist.linux-x86_64/egg/SPARQLWrapper/Wrapper.py", line 537, in _query
  File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen
    return _opener.open(url, data, timeout)
  File "/usr/lib/python2.7/urllib2.py", line 404, in open
    response = self._open(req, data)
  File "/usr/lib/python2.7/urllib2.py", line 422, in _open
    '_open', req)
  File "/usr/lib/python2.7/urllib2.py", line 382, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 1214, in http_open
    return self.do_open(httplib.HTTPConnection, req)
  File "/usr/lib/python2.7/urllib2.py", line 1187, in do_open
    r = h.getresponse(buffering=True)
  File "/usr/lib/python2.7/httplib.py", line 1089, in getresponse
    response.begin()
  File "/usr/lib/python2.7/httplib.py", line 444, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python2.7/httplib.py", line 400, in _read_status
    line = self.fp.readline(_MAXLINE + 1)
  File "/usr/lib/python2.7/socket.py", line 476, in readline
    data = self._sock.recv(self._rbufsize)
socket.error: [Errno 104] Connection reset by peer
dayures commented 6 years ago

Interesting behaviour. I made some testing using the same query, using SPARQLWrapper, but changing the prefix declaration:

Maybe the server is sending a "RST packet". Could you check the log of the server ?

noorbakerally commented 6 years ago

No the request doesn't even go to the server, in fact got the same problem with jena yesterday and reported it on the mailing list [1], as you said removing prefix works, i did this and it works, I believe it's when generating the request to send to the server, for example in the query, if you remove %2C%20 https://bistrotdepays.opendatasoft.com/id/theme/Sport%2C%20Loisirs from https://bistrotdepays.opendatasoft.com/id/theme/Sport%2C%20Loisirs, it works even with the prefix

1. https://lists.apache.org/thread.html/07f2f120419aadaaedf2f3f3d5e2ee4d4e0d6590fc0e9adb13daccc2@%3Cusers.jena.apache.org%3E

On Fri, Nov 24, 2017 at 2:34 PM, dayures notifications@github.com wrote:

Interesting behaviour. I made some testing using the same query, using SPARQLWrapper, but changing the prefix declaration:

  • Removing all the prefixes declared: working
  • Keeping just one prefix (random one): working
  • Keeping more than one prefix: not working!
  • Using more than one prefix in another sparql endpoint (dbpedia): working

Maybe the server is sending a "RST packet". Could you check the log of the server ?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/RDFLib/sparqlwrapper/issues/95#issuecomment-346829846, or mute the thread https://github.com/notifications/unsubscribe-auth/ABHg-mesvZhQmpLI8DcMI7_vHLrdd6U3ks5s5sXPgaJpZM4QptBc .