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

TLS changes in Python 3.10, insecure endpoint #217

Open
milan252525 opened this issue Mar 31, 2022 · 0 comments
Open

TLS changes in Python 3.10, insecure endpoint #217

milan252525 opened this issue Mar 31, 2022 · 0 comments

Comments

@milan252525
Copy link

I'm trying to use this library with the latest Python version (3.10.4).

There were several changes to TLS settings of Python 3.10 (Issue43998)

The problem is I'm querying SPARQL endpoint with now insecure cipher settings. I attached an SSL error bellow.
The endpoint is https://rpp-opendata.egon.gov.cz/odrpp/sparql.

This can be fixed by editing the library to pass SSLContext to urllib.request.ulropen in the following way:

in SPARQLWrapper._query():

import ssl

ctx = ssl.create_default_context()
ctx.set_ciphers("DEFAULT")

try:
            if self.timeout:
                response = urlopener(request, timeout=self.timeout, context=ctx)
            else:
                response = urlopener(request, context=ctx)
            return response, self.returnFormat
...

But this obviously requires changing library code. Would it be possible to update the library to accept a context from outside?

Error:

Traceback (most recent call last):
  File "path1\venv\lib\site-packages\flask\app.py", line 2077, in wsgi_app
    response = self.full_dispatch_request()
  File "path1\venv\lib\site-packages\flask\app.py", line 1525, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "path1\venv\lib\site-packages\flask\app.py", line 1523, in full_dispatch_request
    rv = self.dispatch_request()
  File "path1\venv\lib\site-packages\flask\app.py", line 1509, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "path1\app\controller\routes.py", line 79, in main_page
    recommended = app.requester.get_services_by_keywords(keywords, limit=16)
  File "path1\app\model\service_requester.py", line 108, in get_services_by_keywords
    results = sparql.query().convert()
  File "path1\venv\lib\site-packages\SPARQLWrapper\Wrapper.py", line 1112, in query
    return QueryResult(self._query())
  File "path1\venv\lib\site-packages\SPARQLWrapper\Wrapper.py", line 1078, in _query
    response = urlopener(request)
  File "path2\Python310\lib\urllib\request.py", line 216, in urlopen
    return opener.open(url, data, timeout)
  File "path2\Python310\lib\urllib\request.py", line 519, in open
    response = self._open(req, data)
  File "path2\Python310\lib\urllib\request.py", line 536, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "path2\Python310\lib\urllib\request.py", line 496, in _call_chain
    result = func(*args)
  File "path2\Python310\lib\urllib\request.py", line 1391, in https_open
    return self.do_open(http.client.HTTPSConnection, req,
  File "path2\Python310\lib\urllib\request.py", line 1351, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:997)>
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

1 participant