SPARQLWrapper HTTPAuth Basic - PullRequest
       79

SPARQLWrapper HTTPAuth Basic

0 голосов
/ 16 июня 2020

Я пытаюсь подключиться к конечной точке с помощью http basi c auth. Я не могу заставить его работать.

import rdflib
from SPARQLWrapper import SPARQLWrapper, POST, BASIC, JSON

sparql = SPARQLWrapper(
    "https://www.sample.url/sample/sparql")

sparql.setHTTPAuth(BASIC)
sparql.setCredentials("Basic", "28qUTeC8CI4sEvLiLbtrbCSgMHolK2KyX1xAdUiHOuTiEEF3x5t8Ba1qupVXu9WZ6GD6qpj92VpRPZA1aRlceIbaRWo4CEMh")
sparql.setMethod(POST)
sparql.setQuery("""PREFIX rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos:  <http://www.w3.org/2004/02/skos/core#>
PREFIX owl:  <http://www.w3.org/2002/07/owl#>
PREFIX base: <https://w3id.org/def/basicsemantics-owl#>
PREFIX sh: <http://www.w3.org/ns/shacl#>

SELECT ?uri ?definitie ?omschrijving
WHERE {
  ?uri rdf:type ?type .
  VALUES ?type {owl:ObjectProperty} .
  ?uri skos:prefLabel ?definitie .
  OPTIONAL {
  ?uri skos:definition ?omschrijving .
  }
}""")
sparql.setReturnFormat(JSON)
results = sparql.query().convert()

Что мне здесь не хватает?

добавлен остаток примера запроса sparql, у меня он работает в почтальоне.

Ответы [ 2 ]

0 голосов
/ 16 июня 2020

здесь у меня есть запрос почтальона в python, так что вы можете проверить его основную c http auth

рабочий почтальон python запрос

0 голосов
/ 16 июня 2020

я получаю следующую ошибку

Traceback (most recent call last):
  File "C:\Python38\lib\site-packages\SPARQLWrapper\Wrapper.py", line 1073, in _query
    response = urlopener(request)
  File "C:\Python38\lib\urllib\request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Python38\lib\urllib\request.py", line 531, in open
    response = meth(req, response)
  File "C:\Python38\lib\urllib\request.py", line 640, in http_response
    response = self.parent.error(
  File "C:\Python38\lib\urllib\request.py", line 569, in error
    return self._call_chain(*args)
  File "C:\Python38\lib\urllib\request.py", line 502, in _call_chain
    result = func(*args)
  File "C:\Python38\lib\urllib\request.py", line 649, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 401: 

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\projects\waternet\data rwzi weesp\wotl-properties.py", line 28, in <module>
    results = sparql.query().convert()
  File "C:\Python38\lib\site-packages\SPARQLWrapper\Wrapper.py", line 1107, in query
    return QueryResult(self._query())
  File "C:\Python38\lib\site-packages\SPARQLWrapper\Wrapper.py", line 1081, in _query
    raise Unauthorized(e.read())
SPARQLWrapper.SPARQLExceptions.Unauthorized: Unauthorized: access is denied due to invalid credentials (unauthorized). Check the credentials.
...