From 54f88cc75c05cf76aedb79d8acd70d8186e0df10 Mon Sep 17 00:00:00 2001 From: Clemens Weissbacher <4752766+weimens@users.noreply.github.com> Date: Thu, 25 Oct 2018 11:18:43 +0200 Subject: [PATCH] py3: Arch: fix import urllib2 problem --- src/Mod/Arch/ArchCommands.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Mod/Arch/ArchCommands.py b/src/Mod/Arch/ArchCommands.py index d2561f264e..5f9b1db9f5 100644 --- a/src/Mod/Arch/ArchCommands.py +++ b/src/Mod/Arch/ArchCommands.py @@ -654,7 +654,11 @@ 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.''' - import urllib2, os + try: + from urllib.request import urlopen + except ImportError: + from urllib2 import urlopen + import os name = url.split('/')[-1] p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macro") macropath = p.GetString("MacroPath","") @@ -665,7 +669,7 @@ def download(url,force=False): return filepath try: FreeCAD.Console.PrintMessage("downloading "+url+" ...\n") - response = urllib2.urlopen(url) + response = urlopen(url) s = response.read() f = open(filepath,'wb') f.write(s)