How to set credentials for federated query with SPARQLWrapper in Python? (i.e. 2nd SPARQL endpoint)

183 Views Asked by At

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:[email protected]/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:[email protected]/sparql>
  {
   ?a owl:sameAs ?s .
   }    
}
"""
query = query_content 
sparql.setQuery(query)
sparql.setReturnFormat(JSON)
results = sparql.query().convert()
print(results)

Many thanks!

0

There are 0 best solutions below