From 3e2df83809ee200d1134f9a7a54fe7fe79b49cf9 Mon Sep 17 00:00:00 2001 From: Quentin Schulz Date: Tue, 7 Apr 2026 19:37:08 +0200 Subject: [PATCH] utils/generate-cyclonedx: better error message when host Python is built without ssl urllib will eventually complain that it does not know what https is: Traceback (most recent call last): File "/buildroot/utils/generate-cyclonedx", line 53, in urllib.request.urlretrieve(SPDX_SCHEMA_URL, SPDX_SCHEMA_PATH) ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/buildroot/build/host/lib/python3.14/urllib/request.py", line 212, in urlretrieve with contextlib.closing(urlopen(url, data)) as fp: ~~~~~~~^^^^^^^^^^^ File "/buildroot/build/host/lib/python3.14/urllib/request.py", line 187, in urlopen return opener.open(url, data, timeout) ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^ File "/buildroot/build/host/lib/python3.14/urllib/request.py", line 487, in open response = self._open(req, data) File "/buildroot/build/host/lib/python3.14/urllib/request.py", line 509, in _open return self._call_chain(self.handle_open, 'unknown', ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 'unknown_open', req) ^^^^^^^^^^^^^^^^^^^^ File "/buildroot/build/host/lib/python3.14/urllib/request.py", line 464, in _call_chain result = func(*args) File "/buildroot/build/host/lib/python3.14/urllib/request.py", line 1397, in unknown_open raise URLError('unknown url type: %s' % type) urllib.error.URLError: It's quite confusing really but what it means is that host Python was built without ssl support. This adds an additional check importing _ssl and if the module is not found, tell the user what to do. This still doesn't make Buildroot's host Python3 fully usable for utils/generate-cyclonedx as it'll then fail when trying to validate certificates, this will be handled in the next few commits. Note that ssl Python library is always built in CPython, but itself imports the _ssl module which is the one that may be disabled with py_cv_module__ssl=n/a (which is what happens when BR2_PACKAGE_HOST_PYTHON3_SSL is not enabled), hence why _ssl is checked and not ssl. Signed-off-by: Quentin Schulz Signed-off-by: Arnout Vandecappelle --- utils/generate-cyclonedx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/utils/generate-cyclonedx b/utils/generate-cyclonedx index 611a20127d..7cfeefbc5b 100755 --- a/utils/generate-cyclonedx +++ b/utils/generate-cyclonedx @@ -9,6 +9,7 @@ import argparse +import importlib.util import json import os from pathlib import Path @@ -44,6 +45,11 @@ VULN_WITH_PEDIGREE = set() SPDX_LICENSES = [] if not SPDX_SCHEMA_PATH.exists(): + if not importlib.util.find_spec("_ssl"): + print(f"ssl module required for downloading {SPDX_SCHEMA_URL}. Try enabling BR2_PACKAGE_HOST_PYTHON3_SSL.", + file=sys.stderr) + exit(1) + # Download the CycloneDX SPDX schema JSON, and cache it locally cyclonedxpath.mkdir(parents=True, exist_ok=True) urllib.request.urlretrieve(SPDX_SCHEMA_URL, SPDX_SCHEMA_PATH)