我正在尝试执行以下Sparql查询
select * where {
?s ?p ?o .
} limit 100
它运行良好并根据http://localhost:7200/sparql中的要求生成结果,即GraphDB Workbench . 我想使用python来执行相同的查询,为此我通过在GraphDB界面中单击“获取当前查询的URL”来生成以下查询URL .
http://localhost:7200/sparql?name=&infer=true&sameAs=false&query=select+*+where+%7B+%0A%09%3Fs+%3Fp+%3Fo+.%0A%7D+limit+100+%0A&execute=
我尝试为此编写Python代码
import pycurl
from StringIO import StringIO
url="http://localhost:7200/sparql?name=&infer=true&sameAs=false&query=select+*+where+%7B+%0A%09%3Fs+%3Fp+%3Fo+.%0A%7D+limit+100+%0A&execute="
response_buffer = StringIO()
curl = pycurl.Curl()
curl.setopt(curl.URL,url)
curl.setopt(curl.USERPWD, '%s:%s' % (' ' , ' '))
curl.setopt(curl.WRITEFUNCTION, response_buffer.write)
curl.perform()
curl.close()
response_value = response_buffer.getvalue()
print response_value
但是这会返回:错误 - http状态(404) - 没有消息,请查看服务器日志以获取更多信息
我是否需要进行任何其他设置以在Python中查询GraphDB . 我可以获得一些关于如何使用Python和Sparql查询GraphDB的指导吗?
1 回答
GraphDB数据库为每个RDF存储库公开SPARQL endpoints . 可以从Workbench的界面Setup> Repositories>存储库名称旁边的链接图标(“将存储库复制到剪贴板”)复制正确的SPARQL endpoints 地址 .
您的HTTP请求应如下所示:
其中 %repositoryID% 值是存储库的id .