how to resolve "urllib2.URLError: <urlopen error [Errno 111] Connection refused>"

how to resolve "urllib2.URLError: <urlopen error [Errno 111] Connection refused>"

我在以下位置找到了示例代码 https://github.com/RDFLib/sparqlwrapper/blob/master/scripts/example.py

我稍微修改了一下

from SPARQLWrapper import SPARQLWrapper, JSON, XML, N3, RDF, CSV, TSV
sparql = SPARQLWrapper("http://dbpedia.org/sparql")
sparql.setQuery("""
SELECT ?subject ?predicate ?object
FROM <http://graph.something.com>
FROM <http://ontology.something.com>
WHERE {
?subject ?predicate ?object
} LIMIT 10
""")
# JSON example
print '\n\n*** JSON Example'
sparql.setReturnFormat(JSON)
results = sparql.query().convert()
for result in results["results"]["bindings"]:
print result["label"]["value"]

大部分都不起作用,但当我指向 dbpedia.org 站点时,我需要的部分确实起作用了。但是,当我将其定向到我自己的网站(除我以外任何人都无法访问)时,我收到如下错误:

*** JSON Example Traceback (most recent call last):   File "test01.py", line 29, in <module>
    results = sparql.query().convert()   File "/usr/local/lib/python2.7/dist-packages/SPARQLWrapper/Wrapper.py", line 798, in query
    return QueryResult(self._query())   File "/usr/local/lib/python2.7/dist-packages/SPARQLWrapper/Wrapper.py", line 766, in _query
    response = urlopener(request)   File "/usr/lib/python2.7/urllib2.py", line 154, in urlopen
    return opener.open(url, data, timeout)   File "/usr/lib/python2.7/urllib2.py", line 429, in open
    response = self._open(req, data)   File "/usr/lib/python2.7/urllib2.py", line 447, in _open
    '_open', req)   File "/usr/lib/python2.7/urllib2.py", line 407, in _call_chain
    result = func(*args)   File "/usr/lib/python2.7/urllib2.py", line 1228, in http_open
    return self.do_open(httplib.HTTPConnection, req)   File "/usr/lib/python2.7/urllib2.py", line 1198, in do_open
    raise URLError(err) urllib2.URLError: <urlopen error [Errno 111] Connection refused>

知道发生了什么,更重要的是如何解决它吗?

这是错误的执行部分 --

<urlopen error [Errno 111] Connection refused>

检查您的 Virtuoso 的 [HttpServer] ServerPort(在 INI 文件中设置),并确保您的 Python 客户端可以连接到 Virtuoso 服务器主机上的那个端口。