1

The following code works for me when using Apache Jena Fuseki 4.3.2 (docker image secoresearch/fuseki:4.3.2) with rdflib 6.1.1:

from rdflib import Graph
from rdflib.plugins.stores.sparqlstore import SPARQLUpdateStore

FUSEKI_QUERY = 'http://localhost:3030/ds/sparql'
FUSEKI_UPDATE = 'http://localhost:3030/ds/update'

store = SPARQLUpdateStore(query_endpoint=FUSEKI_QUERY,
                          update_endpoint=FUSEKI_UPDATE,
                          method='POST',
                          autocommit=False)

graph = Graph(store=store, identifier=GRAPH_NAME)
graph.parse('./dump.ttl')  # file containing 1000 example triples
store.commit()

But when I change to OpenLink Virtuoso 07.20.3233 (docker image tenforce/virtuoso:latest), I get the following error: urllib.error.HTTPError: HTTP Error 500: SPARQL Request Failed

With some trial and error, I got the following to work for Virtuoso:

from rdflib import Graph
from rdflib.plugins.stores.sparqlstore import SPARQLUpdateStore

VIRTUOSO_QUERY = 'http://localhost:8890/sparql'
VIRTUOSO_UPDATE = 'http://localhost:8890/sparql'

store = SPARQLUpdateStore(query_endpoint=VIRTUOSO_QUERY,
                          update_endpoint=VIRTUOSO_UPDATE,
                          method='POST',
                          autocommit=False)

intermediate_graph = Graph()
intermediate_graph.parse('./dump.ttl')

graph = Graph(store=store, identifier=GRAPH_NAME)

for triple in intermediate_graph:
    graph.add(triple)
    store.commit()  # Have to commit after every add here

If I don't commit after every add, but only once after the loop, I get the same error as above. At the moment, I don't see any helpful HTTP or server log entries, that might point me to the problem.

So my question is, has anyone an idea why this error occurs and what the solution may be? I guess it has something to do with the way my Virtuoso instance is configured?

Update 03.06.2022:

I noticed, that I was using an old version of Virtuoso with docker image tenforce/virtuoso:latest (07.20.3233), so I switched to openlink/virtuoso-opensource-7:latest (07.20.3234). With that, my code for Virtuoso does not work anymore (same error as stated above).

Also, as TallTed identified correctly in his comment, I use /sparql for both query and update. I can do that, because I gave the user SPARQL the SPARQL_UPDATE role in the Virtuoso Conductor interface. It is kind of a workaround for now, since I didn't get basic auth to work over rdflib. Could that have something to do with the problem, since I don't use /sparql-auth?

Roman
  • 91
  • 5
  • 1
    Does [this](https://gist.github.com/jonlazaro/6934282) help? If not, perhaps raise component-specific issues to their sites, such as [rdflib](https://github.com/RDFLib/rdflib/), [Virtuoso Open Source](https://github.com/openlink/virtuoso-opensource/), or the [OpenLink Community Forum](https://community.openlinksw.com/)? It appears that you've switched off some Virtuoso security features, as you're writing via the `/sparql` endpoint which is read-only by default. This or other Virtuoso config changes you've made *could* explain your experience, but we'd need much more detail to be sure! – TallTed Jun 02 '22 at 19:11
  • Thanks for your fast reply @TallTed. You are right, I use ```/sparql``` for update also. This is a workaround for now, since basic auth does not work for me over ```rdflib```. I just gave the SPARQL user the SPARQL_UPDATE role for that to work. – Roman Jun 03 '22 at 07:14

0 Answers0