From 01e87a2072c97787b8d2197c7b2f6f04f75c2a12 Mon Sep 17 00:00:00 2001 From: Furgo <148809153+furgo16@users.noreply.github.com> Date: Thu, 16 Oct 2025 08:17:31 +0200 Subject: [PATCH 1/2] BIM: remove obsolete Python 2 urllib2 import Python 3 combined the former `urllib`, `urllib2`, `urlparse` Python 2 modules into subpackages of `urllib`. FreeCAD is written in Python 3, thus the `urllib2` import fallback will not work and needs to be removed. --- src/Mod/BIM/ArchCommands.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Mod/BIM/ArchCommands.py b/src/Mod/BIM/ArchCommands.py index d06978bb22..4ee234cc2a 100644 --- a/src/Mod/BIM/ArchCommands.py +++ b/src/Mod/BIM/ArchCommands.py @@ -759,10 +759,7 @@ def download(url, force=False): """download(url,force=False): downloads a file from the given URL and saves it in the macro path. Returns the path to the saved file. If force is True, the file will be downloaded again evn if it already exists.""" - try: - from urllib.request import urlopen - except ImportError: - from urllib2 import urlopen + from urllib.request import urlopen import os name = url.split("/")[-1] From f1b8c0dba38ad7d645758df22b4243f81d4b237c Mon Sep 17 00:00:00 2001 From: Furgo <148809153+furgo16@users.noreply.github.com> Date: Thu, 16 Oct 2025 21:21:18 +0200 Subject: [PATCH 2/2] BIM: replace obsolete urllib2 in BimTutorial --- src/Mod/BIM/bimcommands/BimTutorial.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Mod/BIM/bimcommands/BimTutorial.py b/src/Mod/BIM/bimcommands/BimTutorial.py index 6a8c5469a9..d7b90ba8d4 100644 --- a/src/Mod/BIM/bimcommands/BimTutorial.py +++ b/src/Mod/BIM/bimcommands/BimTutorial.py @@ -97,11 +97,7 @@ class BIM_Tutorial: import codecs import re import sys - - if sys.version_info.major < 3: - import urllib2 - else: - import urllib.request as urllib2 + from urllib.request import urlopen # initial loading @@ -111,7 +107,7 @@ class BIM_Tutorial: # load tutorial from wiki offlineloc = os.path.join(FreeCAD.getUserAppDataDir(), "BIM", "Tutorial", "Tutorial.html") try: - u = urllib2.urlopen(URL) + u = urlopen(URL) html = u.read() if sys.version_info.major >= 3: html = html.decode("utf8") @@ -183,7 +179,7 @@ class BIM_Tutorial: fullpath = "https://www.freecadweb.org/wiki" + path else: fullpath = path - u = urllib2.urlopen(fullpath) + u = urlopen(fullpath) imagedata = u.read() f = open(storename, "wb") f.write(imagedata)