RDFLib / sparqlwrapper

A wrapper for a remote SPARQL endpoint
https://sparqlwrapper.readthedocs.io/
Other
513 stars 121 forks source link

urlopen error [Errno 99] Address not available #141

Closed ahmad88me closed 3 years ago

ahmad88me commented 4 years ago

I am running the code inside docker. For some queries I got this error urlopen error [Errno 99] Address not available. But when I retry the same query again, it seems to work.

The query (on DBpedia)

select distinct ?c where{
        <http://www.wikidata.org/entity/Q51884> a ?c
        }

The python code (attached)

from SPARQLWrapper import SPARQLWrapper, JSON

def run_query_once(query, endpoint):
    """
    :param query: raw SPARQL query
    :param endpoint: endpoint source that hosts the data
    :return: query result as a dict
    """
    sparql = SPARQLWrapper(endpoint=endpoint)
    sparql.setQuery(query=query)
    sparql.setMethod("POST")
    sparql.setReturnFormat(JSON)
    try:
        results = sparql.query().convert()
        if len(results["results"]["bindings"]) > 0:
            return results["results"]["bindings"]
        else:
            logger.debug("returns 0 rows")
            logger.debug("query: <%s>" % str(query).strip())
            return []
    except Exception as e:
        logger.warning(str(e))
        logger.warning("sparql error: $$<%s>$$" % str(e))
        logger.warning("query: $$<%s>$$" % str(query))
        return None

query = """
select distinct ?c where{
        <http://www.wikidata.org/entity/Q51884> a ?c
        }
"""
endpoint = "http://dbpedia.org/sparql"
r = run_query_once(query, endpoint)
print(r)
dayures commented 4 years ago

Maybe it could be an issue in dbpedia availability. Did you try to check the endpoint availability in advance?

ahmad88me commented 4 years ago

When I added randomised wait for the queries that failed it worked.

dayures commented 3 years ago

Thanks for contributing to this issue. As it has been more than 90 days since the last activity, we are automatically closing the issue. This is often because the request was already solved in some way and it just wasn't updated or it's no longer applicable. If that's not the case, please do feel free to either reopen this issue or open a new one. We'll gladly take a look again!