Slicer fails to download custom sample data

I have this code:

which results in a download error:


The file can be downloaded using Chrome and curl.exe. What is wrong?

What version of Slicer are you using?

5.2.1 official release. But the same thing happens with 5.3.0-2022-12-14 3d62cbf.

Hmm, that preview build should have this version of the cert. But maybe check the current preview version?

The same error happens with the latest nightly (5.3.0-2023-03-22 r31691 / fbc2ede).

The following snippet allows to directly test without having to explicitly register a SampleDataSource:

import os

from SampleData import SampleDataLogic

print(f"RemoteCacheDirectory: {slicer.mrmlScene.GetCacheManager().GetRemoteCacheDirectory()}")

file_sha512 = "b648140f38d2c3189388a35fea65ef3b4311237de8c454c6b98480d84b139ec8afb8ec5881c5d9513cdc208ae781e1e442988be81564adff77edcfb30b921a28"

# Download
SampleDataLogic().downloadFileIntoCache(
    f"https://data.kitware.com:443/api/v1/file/hashsum/SHA512/{file_sha512}/download",
    "uniform_phantom_8.9_MHz.mha",
    f'SHA512:{file_sha512}')

# Load into the scene
filePath = os.path.join(slicer.mrmlScene.GetCacheManager().GetRemoteCacheDirectory(), "uniform_phantom_8.9_MHz.mha")
SampleDataLogic().loadNode(filePath, "uniform_phantom_8")

:white_check_mark: The code above works as expected using the latest nightly on Linux (Slicer-5.3.0-2023-03-22)

:white_check_mark: Download using the installed version on Windows also seems to work (from within kitware network):

To summarize, I confirm the download works as expected after installing the following versions:

Version Linux macOS Windows
5.2.1 :question: :question: :white_check_mark:
5.2.2 :white_check_mark: :question: :white_check_mark:
5.3.0-2023-03-22 :white_check_mark: :question: :white_check_mark: (*)

(*) This one was tested inside & outside the kitware network and downloads works from both

Using your test script (pasting into Slicer’s Python console), I get an error:

Python 3.9.10 (main, Mar 23 2023, 23:31:17) [MSC v.1930 64 bit (AMD64)] on win32
>>> 
import os

from SampleData import SampleDataLogic

print(f"RemoteCacheDirectory: {slicer.mrmlScene.GetCacheManager().GetRemoteCacheDirectory()}")

file_sha512 = "b648140f38d2c3189388a35fea65ef3b4311237de8c454c6b98480d84b139ec8afb8ec5881c5d9513cdc208ae781e1e442988be81564adff77edcfb30b921a28"

# Download
SampleDataLogic().downloadFileIntoCache(
    f"https://data.kitware.com:443/api/v1/file/hashsum/SHA512/{file_sha512}/download",
    "uniform_phantom_8.9_MHz.mha",
    f'SHA512:{file_sha512}')

# Load into the scene
filePath = os.path.join(slicer.mrmlScene.GetCacheManager().GetRemoteCacheDirectory(), "uniform_phantom_8.9_MHz.mha")
SampleDataLogic().loadNode(filePath, "uniform_phantom_8")
RemoteCacheDirectory: C:/Users/Dzenan/AppData/Local/slicer.org/Slicer/cache/SlicerIO
Traceback (most recent call last):
  File "C:\Users\Dzenan\AppData\Local\slicer.org\Slicer 5.3.0-2023-03-22\lib\Python\Lib\urllib\request.py", line 1346, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
  File "C:\Users\Dzenan\AppData\Local\slicer.org\Slicer 5.3.0-2023-03-22\lib\Python\Lib\http\client.py", line 1285, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "C:\Users\Dzenan\AppData\Local\slicer.org\Slicer 5.3.0-2023-03-22\lib\Python\Lib\http\client.py", line 1331, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "C:\Users\Dzenan\AppData\Local\slicer.org\Slicer 5.3.0-2023-03-22\lib\Python\Lib\http\client.py", line 1280, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "C:\Users\Dzenan\AppData\Local\slicer.org\Slicer 5.3.0-2023-03-22\lib\Python\Lib\http\client.py", line 1040, in _send_output
    self.send(msg)
  File "C:\Users\Dzenan\AppData\Local\slicer.org\Slicer 5.3.0-2023-03-22\lib\Python\Lib\http\client.py", line 980, in send
    self.connect()
  File "C:\Users\Dzenan\AppData\Local\slicer.org\Slicer 5.3.0-2023-03-22\lib\Python\Lib\http\client.py", line 1454, in connect
    self.sock = self._context.wrap_socket(self.sock,
  File "C:\Users\Dzenan\AppData\Local\slicer.org\Slicer 5.3.0-2023-03-22\lib\Python\Lib\ssl.py", line 500, in wrap_socket
    return self.sslsocket_class._create(
  File "C:\Users\Dzenan\AppData\Local\slicer.org\Slicer 5.3.0-2023-03-22\lib\Python\Lib\ssl.py", line 1040, in _create
    self.do_handshake()
  File "C:\Users\Dzenan\AppData\Local\slicer.org\Slicer 5.3.0-2023-03-22\lib\Python\Lib\ssl.py", line 1309, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1129)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/Dzenan/AppData/Local/slicer.org/Slicer 5.3.0-2023-03-22/bin/../lib/Slicer-5.3/qt-scripted-modules/SampleData.py", line 862, in downloadFile
    urllib.request.urlretrieve(uri, filePath, self.reportHook)
  File "C:\Users\Dzenan\AppData\Local\slicer.org\Slicer 5.3.0-2023-03-22\lib\Python\Lib\urllib\request.py", line 239, in urlretrieve
    with contextlib.closing(urlopen(url, data)) as fp:
  File "C:\Users\Dzenan\AppData\Local\slicer.org\Slicer 5.3.0-2023-03-22\lib\Python\Lib\urllib\request.py", line 214, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Users\Dzenan\AppData\Local\slicer.org\Slicer 5.3.0-2023-03-22\lib\Python\Lib\urllib\request.py", line 517, in open
    response = self._open(req, data)
  File "C:\Users\Dzenan\AppData\Local\slicer.org\Slicer 5.3.0-2023-03-22\lib\Python\Lib\urllib\request.py", line 534, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "C:\Users\Dzenan\AppData\Local\slicer.org\Slicer 5.3.0-2023-03-22\lib\Python\Lib\urllib\request.py", line 494, in _call_chain
    result = func(*args)
  File "C:\Users\Dzenan\AppData\Local\slicer.org\Slicer 5.3.0-2023-03-22\lib\Python\Lib\urllib\request.py", line 1389, in https_open
    return self.do_open(http.client.HTTPSConnection, req,
  File "C:\Users\Dzenan\AppData\Local\slicer.org\Slicer 5.3.0-2023-03-22\lib\Python\Lib\urllib\request.py", line 1349, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1129)>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 10, in <module>
  File "C:/Users/Dzenan/AppData/Local/slicer.org/Slicer 5.3.0-2023-03-22/bin/../lib/Slicer-5.3/qt-scripted-modules/SampleData.py", line 631, in downloadFileIntoCache
    return self.downloadFile(uri, destFolderPath, name, checksum)
  File "C:/Users/Dzenan/AppData/Local/slicer.org/Slicer 5.3.0-2023-03-22/bin/../lib/Slicer-5.3/qt-scripted-modules/SampleData.py", line 866, in downloadFile
    raise ValueError(f"Failed to download {uri} to {filePath}")
ValueError: Failed to download https://data.kitware.com:443/api/v1/file/hashsum/SHA512/b648140f38d2c3189388a35fea65ef3b4311237de8c454c6b98480d84b139ec8afb8ec5881c5d9513cdc208ae781e1e442988be81564adff77edcfb30b921a28/download to C:/Users/Dzenan/AppData/Local/slicer.org/Slicer/cache/SlicerIO/uniform_phantom_8.9_MHz.mha
[Python] <b>	Download failed: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1129)></b>
>>> 

Once the current Slicer incremental build finishes, I will try restarting the computer.

Could you try the following ?

The snippet is expected to work in both PythonSlicer and a regular python interpreter.

import sys
import traceback
import urllib.request


def processEvents():
    try:
        import slicer
        slicer.app.processEvents()
    except (AttributeError, ImportError):
        pass

    
def display(text, file=sys.stdout):
    processEvents()
    print(text, flush=True, file=file)

    
def error(text):
    display(text, file=sys.stderr)


for url, expected_success in [
    ("https://data.kitware.com", True),
    ("https://www.httpvshttps.com/", True),
    ("https://slicer.org/", True),
    ("https://expired.badssl.com/", False),
    ("https://github.com/", True),
]:
    display("-" * 8)
    display(f"Checking {url}")
    try:
        with urllib.request.urlopen(url) as response:
           data = response.read()
           html = data.decode('utf8')
           assert "<head>" in html[:600]
        if expected_success:
            display(f"Checking {url} - OK")
        else:
            error(f"Checking {url} - FAILED - should have raised an exception")
    except Exception as exc:
        if expected_success:
            error(f"Checking {url} - FAILED - unexpected exception")
            traceback.print_exc()
        else:
            display(f"Checking {url} - OK  [Expected {exc}]")

Expected output:

--------
Checking https://data.kitware.com
Checking https://data.kitware.com - ok
--------
Checking https://www.httpvshttps.com/
Checking https://www.httpvshttps.com/ - ok
--------
Checking https://slicer.org/
Checking https://slicer.org/ - ok
--------
Checking https://expired.badssl.com/
Checking https://expired.badssl.com/ - ok  [Expected <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1129)>]
--------
Checking https://github.com/
Checking https://github.com/ - OK

I can confirm that all three of the macOS versions listed generate the expected results when running that script on my machine.

1 Like

From Slicer 5.2.2

-------------
Checking https://data.kitware.com
Checking https://data.kitware.com - OK

--------
Checking https://www.httpvshttps.com/
Checking https://www.httpvshttps.com/ - OK
--------
Checking https://slicer.org/
Checking https://slicer.org/ - OK
--------

Checking https://expired.badssl.com/
Checking https://expired.badssl.com/ - OK [Expected <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1129)>]

--------

Checking https://github.com/
Checking https://github.com/ - OK

>>>

Same from Powershell Windows 11:

--------
Checking https://data.kitware.com
Checking https://data.kitware.com - OK
--------
Checking https://www.httpvshttps.com/
Checking https://www.httpvshttps.com/ - OK
--------
Checking https://slicer.org/
Checking https://slicer.org/ - OK
--------
Checking https://expired.badssl.com/
Checking https://expired.badssl.com/ - OK  [Expected <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1129)>]
--------
Checking https://github.com/
Checking https://github.com/ - OK

Most often this kind of errors are due to overly aggressive firewalls/proxy servers/special network (mis)configuration to use custom SSL certificates, etc. But in this case the network seems to be OK because @jcfr on the same network and same operating system does not have any issue. @dzenanz can you confirm that you have this issue when your computer is on the same network?

If they are on the same network then it must be something special on your computer. Maybe you could try Dependency Walker to see if a wrong SSL DLL is loaded. It would be also interesting to know if others on the same network and same operating system have the same issue as you.

Computer still not restarted. Outputs from JC’s script:

Microsoft Windows [Version 10.0.22621.1413]
(c) Microsoft Corporation. All rights reserved.

C:\Users\Dzenan>python
Python 3.9.13 (tags/v3.9.13:6de2ca5, May 17 2022, 16:36:42) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> import traceback
>>> import urllib.request
>>>
>>>
>>> def processEvents():
...     try:
...         import slicer
...         slicer.app.processEvents()
...     except (AttributeError, ImportError):
...         pass
...
>>>
>>> def display(text, file=sys.stdout):
...     processEvents()
...     print(text, flush=True, file=file)
...
>>>
>>> def error(text):
...     display(text, file=sys.stderr)
...
>>>
>>> for url, expected_success in [
...     ("https://data.kitware.com", True),
...     ("https://www.httpvshttps.com/", True),
...     ("https://slicer.org/", True),
...     ("https://expired.badssl.com/", False),
...     ("https://github.com/", True),
... ]:
...     display("-" * 8)
...     display(f"Checking {url}")
...     try:
...         with urllib.request.urlopen(url) as response:
...            data = response.read()
...            html = data.decode('utf8')
...            assert "<head>" in html[:600]
...         if expected_success:
...             display(f"Checking {url} - OK")
...         else:
...             error(f"Checking {url} - FAILED - should have raised an exception")
...     except Exception as exc:
...         if expected_success:
...             error(f"Checking {url} - FAILED - unexpected exception")
...             traceback.print_exc()
...         else:
...             display(f"Checking {url} - OK  [Expected {exc}]")
...
--------
Checking https://data.kitware.com
Checking https://data.kitware.com - FAILED - unexpected exception
Traceback (most recent call last):
  File "C:\Program Files\Python39\lib\urllib\request.py", line 1346, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
  File "C:\Program Files\Python39\lib\http\client.py", line 1285, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "C:\Program Files\Python39\lib\http\client.py", line 1331, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "C:\Program Files\Python39\lib\http\client.py", line 1280, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "C:\Program Files\Python39\lib\http\client.py", line 1040, in _send_output
    self.send(msg)
  File "C:\Program Files\Python39\lib\http\client.py", line 980, in send
    self.connect()
  File "C:\Program Files\Python39\lib\http\client.py", line 1454, in connect
    self.sock = self._context.wrap_socket(self.sock,
  File "C:\Program Files\Python39\lib\ssl.py", line 501, in wrap_socket
    return self.sslsocket_class._create(
  File "C:\Program Files\Python39\lib\ssl.py", line 1041, in _create
    self.do_handshake()
  File "C:\Program Files\Python39\lib\ssl.py", line 1310, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1129)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 11, in <module>
  File "C:\Program Files\Python39\lib\urllib\request.py", line 214, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Program Files\Python39\lib\urllib\request.py", line 517, in open
    response = self._open(req, data)
  File "C:\Program Files\Python39\lib\urllib\request.py", line 534, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "C:\Program Files\Python39\lib\urllib\request.py", line 494, in _call_chain
    result = func(*args)
  File "C:\Program Files\Python39\lib\urllib\request.py", line 1389, in https_open
    return self.do_open(http.client.HTTPSConnection, req,
  File "C:\Program Files\Python39\lib\urllib\request.py", line 1349, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1129)>
--------
Checking https://www.httpvshttps.com/
Checking https://www.httpvshttps.com/ - FAILED - unexpected exception
Traceback (most recent call last):
  File "C:\Program Files\Python39\lib\urllib\request.py", line 1346, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
  File "C:\Program Files\Python39\lib\http\client.py", line 1285, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "C:\Program Files\Python39\lib\http\client.py", line 1331, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "C:\Program Files\Python39\lib\http\client.py", line 1280, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "C:\Program Files\Python39\lib\http\client.py", line 1040, in _send_output
    self.send(msg)
  File "C:\Program Files\Python39\lib\http\client.py", line 980, in send
    self.connect()
  File "C:\Program Files\Python39\lib\http\client.py", line 1454, in connect
    self.sock = self._context.wrap_socket(self.sock,
  File "C:\Program Files\Python39\lib\ssl.py", line 501, in wrap_socket
    return self.sslsocket_class._create(
  File "C:\Program Files\Python39\lib\ssl.py", line 1041, in _create
    self.do_handshake()
  File "C:\Program Files\Python39\lib\ssl.py", line 1310, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1129)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 11, in <module>
  File "C:\Program Files\Python39\lib\urllib\request.py", line 214, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Program Files\Python39\lib\urllib\request.py", line 517, in open
    response = self._open(req, data)
  File "C:\Program Files\Python39\lib\urllib\request.py", line 534, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "C:\Program Files\Python39\lib\urllib\request.py", line 494, in _call_chain
    result = func(*args)
  File "C:\Program Files\Python39\lib\urllib\request.py", line 1389, in https_open
    return self.do_open(http.client.HTTPSConnection, req,
  File "C:\Program Files\Python39\lib\urllib\request.py", line 1349, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1129)>
--------
Checking https://slicer.org/
Checking https://slicer.org/ - FAILED - unexpected exception
Traceback (most recent call last):
  File "C:\Program Files\Python39\lib\urllib\request.py", line 1346, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
  File "C:\Program Files\Python39\lib\http\client.py", line 1285, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "C:\Program Files\Python39\lib\http\client.py", line 1331, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "C:\Program Files\Python39\lib\http\client.py", line 1280, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "C:\Program Files\Python39\lib\http\client.py", line 1040, in _send_output
    self.send(msg)
  File "C:\Program Files\Python39\lib\http\client.py", line 980, in send
    self.connect()
  File "C:\Program Files\Python39\lib\http\client.py", line 1454, in connect
    self.sock = self._context.wrap_socket(self.sock,
  File "C:\Program Files\Python39\lib\ssl.py", line 501, in wrap_socket
    return self.sslsocket_class._create(
  File "C:\Program Files\Python39\lib\ssl.py", line 1041, in _create
    self.do_handshake()
  File "C:\Program Files\Python39\lib\ssl.py", line 1310, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1129)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 11, in <module>
  File "C:\Program Files\Python39\lib\urllib\request.py", line 214, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Program Files\Python39\lib\urllib\request.py", line 517, in open
    response = self._open(req, data)
  File "C:\Program Files\Python39\lib\urllib\request.py", line 534, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "C:\Program Files\Python39\lib\urllib\request.py", line 494, in _call_chain
    result = func(*args)
  File "C:\Program Files\Python39\lib\urllib\request.py", line 1389, in https_open
    return self.do_open(http.client.HTTPSConnection, req,
  File "C:\Program Files\Python39\lib\urllib\request.py", line 1349, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1129)>
--------
Checking https://expired.badssl.com/
Checking https://expired.badssl.com/ - OK  [Expected <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1129)>]
--------
Checking https://github.com/
Checking https://github.com/ - OK
>>> ^Z


C:\Users\Dzenan>where python
C:\Program Files\Python39\python.exe
C:\Program Files\Python311\python.exe
C:\Users\Dzenan\AppData\Local\Microsoft\WindowsApps\python.exe

C:\Users\Dzenan>"C:\Program Files\Python311\python.exe"
Python 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> import traceback
>>> import urllib.request
>>>
>>>
>>> def processEvents():
...     try:
...         import slicer
...         slicer.app.processEvents()
...     except (AttributeError, ImportError):
...         pass
...
>>>
>>> def display(text, file=sys.stdout):
...     processEvents()
...     print(text, flush=True, file=file)
...
>>>
>>> def error(text):
...     display(text, file=sys.stderr)
...
>>>
>>> for url, expected_success in [
...     ("https://data.kitware.com", True),
...     ("https://www.httpvshttps.com/", True),
...     ("https://slicer.org/", True),
...     ("https://expired.badssl.com/", False),
...     ("https://github.com/", True),
... ]:
...     display("-" * 8)
...     display(f"Checking {url}")
...     try:
...         with urllib.request.urlopen(url) as response:
...            data = response.read()
...            html = data.decode('utf8')
...            assert "<head>" in html[:600]
...         if expected_success:
...             display(f"Checking {url} - OK")
...         else:
...             error(f"Checking {url} - FAILED - should have raised an exception")
...     except Exception as exc:
...         if expected_success:
...             error(f"Checking {url} - FAILED - unexpected exception")
...             traceback.print_exc()
...         else:
...             display(f"Checking {url} - OK  [Expected {exc}]")
...
--------
Checking https://data.kitware.com
Checking https://data.kitware.com - FAILED - unexpected exception
Traceback (most recent call last):
  File "C:\Program Files\Python311\Lib\urllib\request.py", line 1348, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
  File "C:\Program Files\Python311\Lib\http\client.py", line 1282, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "C:\Program Files\Python311\Lib\http\client.py", line 1328, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "C:\Program Files\Python311\Lib\http\client.py", line 1277, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "C:\Program Files\Python311\Lib\http\client.py", line 1037, in _send_output
    self.send(msg)
  File "C:\Program Files\Python311\Lib\http\client.py", line 975, in send
    self.connect()
  File "C:\Program Files\Python311\Lib\http\client.py", line 1454, in connect
    self.sock = self._context.wrap_socket(self.sock,
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\ssl.py", line 517, in wrap_socket
    return self.sslsocket_class._create(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\ssl.py", line 1075, in _create
    self.do_handshake()
  File "C:\Program Files\Python311\Lib\ssl.py", line 1346, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:992)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 11, in <module>
  File "C:\Program Files\Python311\Lib\urllib\request.py", line 216, in urlopen
    return opener.open(url, data, timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\urllib\request.py", line 519, in open
    response = self._open(req, data)
               ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\urllib\request.py", line 536, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\urllib\request.py", line 496, in _call_chain
    result = func(*args)
             ^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\urllib\request.py", line 1391, in https_open
    return self.do_open(http.client.HTTPSConnection, req,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\urllib\request.py", line 1351, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:992)>
--------
Checking https://www.httpvshttps.com/
Checking https://www.httpvshttps.com/ - FAILED - unexpected exception
Traceback (most recent call last):
  File "C:\Program Files\Python311\Lib\urllib\request.py", line 1348, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
  File "C:\Program Files\Python311\Lib\http\client.py", line 1282, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "C:\Program Files\Python311\Lib\http\client.py", line 1328, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "C:\Program Files\Python311\Lib\http\client.py", line 1277, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "C:\Program Files\Python311\Lib\http\client.py", line 1037, in _send_output
    self.send(msg)
  File "C:\Program Files\Python311\Lib\http\client.py", line 975, in send
    self.connect()
  File "C:\Program Files\Python311\Lib\http\client.py", line 1454, in connect
    self.sock = self._context.wrap_socket(self.sock,
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\ssl.py", line 517, in wrap_socket
    return self.sslsocket_class._create(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\ssl.py", line 1075, in _create
    self.do_handshake()
  File "C:\Program Files\Python311\Lib\ssl.py", line 1346, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:992)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 11, in <module>
  File "C:\Program Files\Python311\Lib\urllib\request.py", line 216, in urlopen
    return opener.open(url, data, timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\urllib\request.py", line 519, in open
    response = self._open(req, data)
               ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\urllib\request.py", line 536, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\urllib\request.py", line 496, in _call_chain
    result = func(*args)
             ^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\urllib\request.py", line 1391, in https_open
    return self.do_open(http.client.HTTPSConnection, req,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\urllib\request.py", line 1351, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:992)>
--------
Checking https://slicer.org/
Checking https://slicer.org/ - FAILED - unexpected exception
Traceback (most recent call last):
  File "C:\Program Files\Python311\Lib\urllib\request.py", line 1348, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
  File "C:\Program Files\Python311\Lib\http\client.py", line 1282, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "C:\Program Files\Python311\Lib\http\client.py", line 1328, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "C:\Program Files\Python311\Lib\http\client.py", line 1277, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "C:\Program Files\Python311\Lib\http\client.py", line 1037, in _send_output
    self.send(msg)
  File "C:\Program Files\Python311\Lib\http\client.py", line 975, in send
    self.connect()
  File "C:\Program Files\Python311\Lib\http\client.py", line 1454, in connect
    self.sock = self._context.wrap_socket(self.sock,
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\ssl.py", line 517, in wrap_socket
    return self.sslsocket_class._create(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\ssl.py", line 1075, in _create
    self.do_handshake()
  File "C:\Program Files\Python311\Lib\ssl.py", line 1346, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:992)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 11, in <module>
  File "C:\Program Files\Python311\Lib\urllib\request.py", line 216, in urlopen
    return opener.open(url, data, timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\urllib\request.py", line 519, in open
    response = self._open(req, data)
               ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\urllib\request.py", line 536, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\urllib\request.py", line 496, in _call_chain
    result = func(*args)
             ^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\urllib\request.py", line 1391, in https_open
    return self.do_open(http.client.HTTPSConnection, req,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\urllib\request.py", line 1351, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:992)>
--------
Checking https://expired.badssl.com/
Checking https://expired.badssl.com/ - OK  [Expected <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:992)>]
--------
Checking https://github.com/
Checking https://github.com/ - OK
>>> ^Z

On my Ubuntu box, the script works as expected. Restarting the computer now.

After restart, the error is still the same in system Python. I will now examine DLLs being loaded.

Exploring dependencies of both System Python, and SlicerApp-real.exe does not reveal anything interesting. JC’s script produces expected output on my laptop with Windows 11 and freshly installed Python 3.11.2.

I will ask Kitware’s sysadmin team for help. Thanks to everyone who has pitched in here.

2 Likes

conda update stopped working, with a different error message. Can some actionable advice be gotten from this?

(M:\Something\env) M:\Something\deep_learning>conda env update --prefix …/env --file environment.yml
Retrieving notices: …working… ERROR conda.notices.fetch:get_channel_notice_response(63): Request error <HTTPSConnectionPool(host=‘repo.anaconda.com’, port=443): Max retries exceeded with url: /pkgs/r/notices.json (Caused by SSLError(“Can’t connect to HTTPS URL because the SSL module is not available.”))> for channel: defaults url: https://repo.anaconda.com/pkgs/r/notices.json
ERROR conda.notices.fetch:get_channel_notice_response(63): Request error <HTTPSConnectionPool(host=‘repo.anaconda.com’, port=443): Max retries exceeded with url: /pkgs/msys2/notices.json (Caused by SSLError(“Can’t connect to HTTPS URL because the SSL module is not available.”))> for channel: defaults url: https://repo.anaconda.com/pkgs/msys2/notices.json
ERROR conda.notices.fetch:get_channel_notice_response(63): Request error <HTTPSConnectionPool(host=‘repo.anaconda.com’, port=443): Max retries exceeded with url: /pkgs/main/notices.json (Caused by SSLError(“Can’t connect to HTTPS URL because the SSL module is not available.”))> for channel: defaults url: https://repo.anaconda.com/pkgs/main/notices.json
done
Collecting package metadata (repodata.json): failed

CondaSSLError: OpenSSL appears to be unavailable on this machine. OpenSSL is required to
download and install packages.

Exception: HTTPSConnectionPool(host=‘conda.anaconda.org’, port=443): Max retries exceeded with url: /pytorch/win-64/repodata.json (Caused by SSLError(“Can’t connect to HTTPS URL because the SSL module is not available.”))

This conda issue is solved by copying some DLLs, so I assume it is unrelated to my Python SSL issue.

It is very hard to tell what’s causing your network problems. Most likely some software is messing with your SSL certifications or OpenSSL libraries. You can try searching for all OpenSSL dll instances on your computer and temporarily rename/remove them to see if it makes any difference (just leaving those in place that you are testing). You can also try logging in as a different user (maybe the troublesome software is only installed for your current user). You can also track down what exactly is happening (what executable files are loaded, what data files (SSL certificates, etc.) are accessed using Process Monitor.

1 Like