Browse Source

Move WFS import to urllib2 to provide better error messages. Fixes https://trac.osgeo.org/grass/ticket/3324

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@70823 15284696-431f-4ddb-bdfa-cd5b030d7da7
Maris Nartiss 8 years ago
parent
commit
ee8c6f93a4
1 changed files with 12 additions and 2 deletions
  1. 12 2
      scripts/v.in.wfs/v.in.wfs.py

+ 12 - 2
scripts/v.in.wfs/v.in.wfs.py

@@ -79,9 +79,10 @@ import sys
 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 @@ def main():
 
     # 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()