0

Python's SPARQLWrapper has setCredentials to specify credentials for SPARQL query, but it is meant for the current SPARQL endpoint. So, I wonder how to specify credentials for 2nd endpoint in the context of federated query, using SERVICE. I tried with simple syntax in SPARQL: http://user2:password2@example2.com/sparql but it does not seem to work. As for the code, I have something like this in Python:

sparql = SPARQLWrapper('https://example1.com/sparql')
sparql.setCredentials("user1", "password1")

query_content = """
SELECT *
WHERE {
  ?s owl:sameAs ?o .
  SERVICE <https://user2:password2@example2.com/sparql>
  {
   ?a owl:sameAs ?s .
   }    
}
"""
query = query_content 
sparql.setQuery(query)
sparql.setReturnFormat(JSON)
results = sparql.query().convert()
print(results)

Many thanks!

user7665853
  • 195
  • 1
  • 15
  • 1
    That is the common approach. SPARQLWrapper does nothing more than sending the whole query to the SPARQL endpoint - the rest is up to the SPARQL endpoint, how it does implement the `SERVICE` keyword, that is nothing where SPARQLWrapper could do anything at all. But usually for BASIC auth what you did with putting it into the URL also how we do, for example to a Fuseki SPARQL endpoint it worked for me. But it implements on the SPARQL endpoint, maybe some also drop parts of the URL accidentially, who knows – UninformedUser Mar 23 '23 at 19:10
  • By the way, what does it mean "does not work"? – UninformedUser Mar 23 '23 at 19:10
  • Thank you for you answer. I got an error like this: Status Code=401, Status Line=Unauthorized, Response=\\n\\tat java.util.concurrent.FutureTask.report(FutureTask.java:122)\\n\\tat java.util.concurrent.FutureTask.get(FutureTask.java:192)\\n\\tat I think it is related to credential settings, because if I use SERVICE SILENT, the query returns a proper result. – user7665853 Mar 24 '23 at 09:12
  • Is there no way to set credentials for SERVICE query outside SPARQL query itself (like what setCredentials does for the main query)? – user7665853 Mar 24 '23 at 09:16
  • 1
    No, I don't see how this should be technically possible. I mean, all you're doing is sending a SPARQL query to a SPARQL endpoint via HTTP. The triple stores does parse the SPARQL query string and then, in your case, also does send another HTTP request to a different SPARQL endpoint. How should it be possible to "inject" any mostly different authorization for "nested" requests? At least **I** don't know such an option, but that doesn't mean anything ... – UninformedUser Mar 27 '23 at 06:15
  • So, to what kind of triple store do you send the main query? – UninformedUser Mar 27 '23 at 06:17
  • Thank you for your information! Appreciated. We use Blazegraph at the moment. – user7665853 Mar 29 '23 at 14:13

0 Answers0