代码之家  ›  专栏  ›  技术社区  ›  elbillaf

如何解决“urllib2.urlerror:<urlopen error[errno 111]连接被拒绝>”

  •  1
  • elbillaf  · 技术社区  · 6 年前

    我发现样本代码在 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>
    

    你知道发生了什么,更重要的是怎么解决吗?

    1 回复  |  直到 6 年前
        1
  •  1
  •   TallTed    6 年前

    这是错误的操作部分--

    <urlopen error [Errno 111] Connection refused>
    

    看看你的艺术大师 [HttpServer] ServerPort (在ini文件中设置),并确保python客户机可以连接到virtuoso服务器主机上的该端口。