From 53d613e5490daf6993c0a60aa56a0393a2f9c179 Mon Sep 17 00:00:00 2001
From: Ondrej Pesek <pesej.ondrek@gmail.com>
Date: Sat, 7 Dec 2024 18:52:40 +0100
Subject: [PATCH 1/3] v.in.wfs: improve error message for ServiceException

the current one said that the downloaded XML cannot be found - report the meaningful content of service exception report instead
---
 scripts/v.in.wfs/v.in.wfs.py | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/scripts/v.in.wfs/v.in.wfs.py b/scripts/v.in.wfs/v.in.wfs.py
index 9f53840edcf..4e6efc0dc62 100755
--- a/scripts/v.in.wfs/v.in.wfs.py
+++ b/scripts/v.in.wfs/v.in.wfs.py
@@ -229,7 +229,14 @@ def main():
             grass.run_command("v.in.ogr", flags="o", input=tmpxml, output=out)
         grass.message(_("Vector map <%s> imported from WFS.") % out)
     except Exception:
+        import xml.etree.ElementTree as ET
+
         grass.message(_("WFS import failed"))
+
+        root = ET.parse(tmpxml).getroot()
+        if "ServiceExceptionReport" in root.tag:
+            se = root.find(root.tag[:-6])  # strip "Report" from the tag
+            grass.message(se.text.strip())
     finally:
         try_remove(tmpxml)
 

From e2d4ef188241f22ff08d6a51e84d110c1fc7fc70 Mon Sep 17 00:00:00 2001
From: Ondrej Pesek <pesej.ondrek@gmail.com>
Date: Sat, 7 Dec 2024 20:47:12 +0100
Subject: [PATCH 2/3] replace xml.etree by the safer defusedxml

---
 scripts/v.in.wfs/v.in.wfs.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/v.in.wfs/v.in.wfs.py b/scripts/v.in.wfs/v.in.wfs.py
index 4e6efc0dc62..ded47f3b50c 100755
--- a/scripts/v.in.wfs/v.in.wfs.py
+++ b/scripts/v.in.wfs/v.in.wfs.py
@@ -229,7 +229,7 @@ def main():
             grass.run_command("v.in.ogr", flags="o", input=tmpxml, output=out)
         grass.message(_("Vector map <%s> imported from WFS.") % out)
     except Exception:
-        import xml.etree.ElementTree as ET
+        import defusedxml.ElementTree as ET
 
         grass.message(_("WFS import failed"))
 

From 230a7ccf6f2433414d12d840f8a641de7de285ce Mon Sep 17 00:00:00 2001
From: Ondrej Pesek <pesej.ondrek@gmail.com>
Date: Wed, 11 Dec 2024 12:25:06 +0100
Subject: [PATCH 3/3] Revert "replace xml.etree by the safer defusedxml"

This reverts commit e2d4ef188241f22ff08d6a51e84d110c1fc7fc70.
---
 scripts/v.in.wfs/v.in.wfs.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/v.in.wfs/v.in.wfs.py b/scripts/v.in.wfs/v.in.wfs.py
index ded47f3b50c..4e6efc0dc62 100755
--- a/scripts/v.in.wfs/v.in.wfs.py
+++ b/scripts/v.in.wfs/v.in.wfs.py
@@ -229,7 +229,7 @@ def main():
             grass.run_command("v.in.ogr", flags="o", input=tmpxml, output=out)
         grass.message(_("Vector map <%s> imported from WFS.") % out)
     except Exception:
-        import defusedxml.ElementTree as ET
+        import xml.etree.ElementTree as ET
 
         grass.message(_("WFS import failed"))