Delete/clear 使用 sparql 的海王星命名图的所有内容

Delete/clear all contents of a neptune named graph using sparql

我正在尝试使用 python 从命名图中 delete/clear 数据。使用的方法

import requests
url = "neptune_endpoint:8182/sparql"
query = "CLEAR GRAPH IRIref."
PARAMS = {"query" :query}
r = requests.get(url, params= PARAMS)

收到错误格式错误的查询。在此先感谢您的帮助。

以下代码应该适合您。

import requests
url = "neptune_url:8182/sparql"
query = "CLEAR GRAPH IRIref"
headers = {"content-type": "application/sparql-update"}
r = requests.post(url, data=query, headers=headers)

请注意,规范要求它是 POST 并且设置了特定的内容类型 headers。 Neptune 完全符合 SPARQL 1.1 标准,因此此处规范中的相关领域是 https://www.w3.org/TR/sparql11-protocol/#update-operation and https://www.w3.org/TR/sparql11-update/#clear.