我试着用http basic 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请求的其余部分,我在postman中也能使用。
我得到以下错误
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.
这里我有Python中的邮递员请求,所以你可以验证它的基本http认证