Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails to execute a query on dbpedia: ssl certificate problem #168

Open
datamusee opened this issue Jun 24, 2021 · 11 comments
Open

Fails to execute a query on dbpedia: ssl certificate problem #168

datamusee opened this issue Jun 24, 2021 · 11 comments

Comments

@datamusee
Copy link

datamusee commented Jun 24, 2021

Hello
I'm used to use SPARQLWrapper with success.
But, today, in my environment, I get the following error
Début de run
Comment :=>> <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)>
and I don't understand how tosolve this problem.
If I directly use urlopen, I can do something like this (unsecure, I know)
unsecurecontext = ssl._create_unverified_context()
... urlopen(urldbpedia, context=unsecurecontext) ...
But, I'm unable to find a method to manage that with SPARQLWrapper, cleanly or uncleanly.

(I know about issue #56, but I doesn't see a solution which apply)
ps: my environment is a virtual lab in a moodle platform

@sven-h
Copy link

sven-h commented Oct 11, 2021

Hi,

I have encountered the same issue.
I traced it down to an SSL error for all pages which uses Let's Encrypt.
Please see also the issue I created on Anaconda.
There is not yet any solution but hopefully someone finds one soon.

Best regards
Sven

@AlasdairGray
Copy link

I have been successfully using myBinder to run a notebook containing SPARQLWrapper code for a few weeks. Towards the end of last week it suddenly stopped working. In trying to get to the bottom of the issue I've found the following error

ERROR:Exception running query: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1091)>

Is this the same issue or is something else going on?

@AlasdairGray
Copy link

There is also #102 which seems to be related.

@sven-h
Copy link

sven-h commented Jan 26, 2022

Hi @AlasdairGray ,
do you have a minimal examples which shows this error?

@AlasdairGray
Copy link

You can fire up this notebook on myBinder, run all the cells then select the first query from the dropdown list of available queries 'Number of Triples', and click Execute.

This throws the exception (not sure why the exception text is not displaying in the UI). You can find the exception text below in the generated log file idpQuery.log.

INFO:Starting processing at 11:45:27.766193
INFO:SPARQL Endpoint: https://swel.macs.hw.ac.uk/data/repositories/bioschemas
INFO:Run query HCLS-Stats-Queries/number-triples.rq
INFO:Executing query in file: HCLS-Stats-Queries/number-triples.rq
ERROR:Exception running query: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1091)>
Query:
 ## Number of Triples

SELECT (COUNT(*) AS ?triples)
WHERE {
    GRAPH ?g {
        ?s ?p ?o
    }
}

options: sparql

The query runs fine when I run it directly through the GraphDB interface, and worked fine up until last week through the notebook. Only change in the notebook is the tweak I made today to the logging so that we can see the error message. Nothing has changed on the server side as far as I'm aware.

@AlasdairGray
Copy link

The corresponding curl command works fine

curl https://swel.macs.hw.ac.uk/data/repositories/bioschemas?query="SELECT%20%28COUNT%28%2A%29%20AS%20%3Ftriples%29%0AWHERE%20%7B%0A%20%20%20%20GRAPH%20%3Fg%20%7B%0A%20%20%20%20%20%20%20%20%3Fs%20%3Fp%20%3Fo%0A%20%20%20%20%7D%0A%7D"

@sven-h
Copy link

sven-h commented Jan 26, 2022

For me the following snippet works fine:

from SPARQLWrapper import SPARQLWrapper, JSON

sparql = SPARQLWrapper("https://swel.macs.hw.ac.uk/data/repositories/bioschemas")
sparql.setQuery("""
    SELECT * WHERE {
        ?s a ?o.
    }
    LIMIT 10
""")
sparql.setReturnFormat(JSON)
ret = sparql.queryAndConvert()
for r in ret["results"]["bindings"]:
    print(r)

@AlasdairGray
Copy link

It seems that things work fine on a Windows machine but not on a Mac (I've been discussing the issue with a colleague), not sure about Linux. We've put in a workaround, but suspect that the underlying cause could be to do with the certificate on the server.

@sraimund
Copy link

@sven-h Your snippet works well. I tried:

sparql = SPARQLWrapper("http://dbpedia.org/sparql")
sparql.setQuery("SELECT DISTINCT ?geometry WHERE {<http://dbpedia.org/resource/Paris> geo:geometry ?geometry}")
sparql.setReturnFormat(JSON)
results = sparql.query().convert()

It works with Python 3.7, but the reported SSL exception is raised using Python 3.8 (also 3.10) on my Windows machine.

@sven-h
Copy link

sven-h commented Apr 12, 2022

Hi,

your script works fine for me:

conda create -n testenv python=3.8
conda activate testenv
pip install sparqlwrapper

Can you check the folder of openssl with openssl version -d (in the activated env) if it contains some files?

@sraimund
Copy link

Hi sven-h, I used virtualenv instead of conda. An openssl binary is not available there. I tried adding pyOpenSSL, but it did not help.

I noticed that sparqlwrapper works fine with Python 3.7.3. But with Python 3.7.4 and higher, the error appears. A workaround, mentioned on stackoverflow, is to add the following lines before the query:

import ssl
ssl._create_default_https_context = ssl._create_unverified_context

Do you have a more elegant solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants