[GRASS-SVN] r70823 - grass/trunk/scripts/v.in.wfs

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Apr 1 06:17:48 PDT 2017


Author: marisn
Date: 2017-04-01 06:17:48 -0700 (Sat, 01 Apr 2017)
New Revision: 70823

Modified:
   grass/trunk/scripts/v.in.wfs/v.in.wfs.py
Log:
Move WFS import to urllib2 to provide better error messages. Fixes #3324


Modified: grass/trunk/scripts/v.in.wfs/v.in.wfs.py
===================================================================
--- grass/trunk/scripts/v.in.wfs/v.in.wfs.py	2017-04-01 12:52:49 UTC (rev 70822)
+++ grass/trunk/scripts/v.in.wfs/v.in.wfs.py	2017-04-01 13:17:48 UTC (rev 70823)
@@ -79,9 +79,10 @@
 from grass.script.utils import try_remove
 from grass.script import core as grass
 try:
-    from urllib import urlopen
+    from urllib2 import urlopen, URLError, HTTPError
 except ImportError:
     from urllib.request import urlopen
+    from urllib.error import URLError, HTTPError
 
 # i18N
 import gettext
@@ -127,7 +128,16 @@
 
     # GTC Downloading WFS features
     grass.message(_("Retrieving data..."))
-    inf = urlopen(wfs_url)
+    try:
+        inf = urlopen(wfs_url)
+    except HTTPError as e:
+        # GTC WFS request HTTP failure
+        grass.fatal(_("The server couldn't fulfill the request.\nError code: %s") % e.code)
+    except URLError as e:
+        # GTC WFS request network failure
+        grass.fatal(_("Failed to reach the server.\nReason: %s") % e.reason)
+        
+    
     outf = file(tmpxml, 'wb')
     while True:
         s = inf.read()



More information about the grass-commit mailing list