我正在嘗試使用 Python requests 模塊從 GraphDB REST API 運行 DELETE 查詢,但沒有運氣。
SELECT 查詢requests.get()作業正常:
query = "http://localhost:7200/repositories/myreponame?name=&infer=true&sameAs=false&query=SELECT ?s ?p ?o
WHERE {
?s ?p ?o .
}
"
response = requests.get(query, headers = {"Authorization" : token})
但每當我切換到 DELETE 查詢時,它就不起作用了。
如果我使用 DELETE 查詢,則會requests.get()收到此錯誤:
query = "http://localhost:7200/repositories/myreponame?name=&infer=true&sameAs=false&query=DELETE {
?s ?p ?o .
}
WHERE {
?s ?p ?o .
}
"
MALFORMED QUERY: Encountered " "delete" "DELETE "" at line 1, column 1.
Was expecting one of:
"base" ...
"prefix" ...
"select" ...
"construct" ...
"describe" ...
"ask" ...
如果我改用 DELETE 查詢requests.delete(),我會得到:
Repository delete error: query supplied with request
我究竟做錯了什么?
我正在以管理員權限訪問 API,所以這不是問題。
編輯: 根據 UninformedUser 的評論,我嘗試切換到 POST 請求,并將 URL 從query修改為update。還添加了此處所述的適當內容型別:
query = "http://localhost:7200/repositories/myreponame?name=&infer=true&sameAs=false&update=DELETE {
?s ?p ?o .
}
WHERE {
?s ?p ?o .
}
"
response = requests.post(query, headers = {"Authorization" : token, "Content-Type": "application/x-www-form-urlencoded"})
現在收到以下錯誤:
Missing parameter: query
uj5u.com熱心網友回復:
原來我錯過了 GraphDB 的一個特定要求:對于更新,必須/statements在存盤庫 ID 之后附加:
query = "http://localhost:7200/repositories/myreponame/statements?name=&infer=true&sameAs=false&update=DELETE {
?s ?p ?o .
}
WHERE {
?s ?p ?o .
}
"
response = requests.post(query, headers = {"Authorization" : token, "Content-Type": "application/x-www-form-urlencoded"})
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/489907.html
