INSERT/DELETE/UPDATE query using SPARQLWrapper

后端 未结 2 1746
孤独总比滥情好
孤独总比滥情好 2021-01-18 09:24

Although I have gone through lot of examples on the web explaining the use of python SPARQLWrapper using SELECT statements for fetching data from sesame triple store, but no

2条回答
  •  无人及你
    2021-01-18 10:06

    The SPARQL queries are send as GET request, but the UPDATE (like INSERT, DELETE, etc.) requires the query be send as a POST request. Just add the following line before sparql.query()

    sparql.method = 'POST'
    

    Also, the url for update is different from the query. The update is based on workbench and not sesame url. For example, if the query url is:

    http://localhost:8080/openrdf-sesame/repositories/test/
    

    or

    http://localhost:8080/openrdf-workbench/repositories/test/query
    

    then the update url would be:

    http://localhost:8080/openrdf-workbench/repositories/test/update
    

    Therefore, the UPDATE/INSERT request should look like:

    queryString = "INSERT DATA { GRAPH  { "b" a "c". } }" 
    sparql = SPARQLWrapper("http://localhost:8080/openrdf-workbench/repositories/test/update")
    
    sparql.setQuery(queryString) 
    sparql.method = 'POST'
    sparql.query()
    

提交回复
热议问题