0

I'm trying to download a lot of datasets from different WFS URLs using ogr2ogr (and to an extent, owslib) in Python. My problem arises when I try to connect to a second WFS.

In my test code, I have first tried connecting to one WFS, then downloading the layer. This went fine. Afterwards, I replaced the URL with a second WFS URL. this time I got the error:

ConnectionError: ('Connection aborted.', ConnectionResetError(10054 An existing connection was forcibly closed by the remote host)). 

In the first part of the code I try to extract the version number from the WFS:

import subprocess
from owslib.wfs import WebFeatureService as wfsmod

#connecting to second WFS using owslib
url = 'http://wfs2-miljoegis.mim.dk/raastofpaahavet/ows? 
version=1.1.0&OUTPUTFORMAT=GML2'
wfs = wfsmod(url)
version =  (wfs.identification.version)
typenam ="rashavtilladelser20auktion"

The connection error happens at line "wfs = wfsmod(url)".

I also try to download a specific layer from this url using ogr2ogr/subprocesses:

if str(version) == "2.0.0":
    #layername is the specific title of the layer on the WFS server.
    layername = "&TYPENAMES="+layername
else:
    layername = "&TYPENAME="+layername

cmd =  [r"C:\OSGeo4W\bin\ogr2ogr.exe", 
    "-f",
    "ESRI Shapefile", 
    r"C:\havplan\havplan_data\wfs_downloads\havbrugszoner.shp", 
     "WFS:"+url+"version="+str(version)
     +"&request=GetFeature"+layername]
subprocess.check_call(cmd)

as far as I understand, the error happens because I can only connect to one WFS at a time in Python. Is there some way to close the connection to a WFS in owslib and ogr2ogr using a command?

  • If you ask for a version 1.1.0 as part of the URL, how can you expect any response other than version 1.1.0 or error if the server doesn't support that version? – nmtoken Jul 16 '18 at 10:05
  • As an aside on KVP syntax the OGC specs tell us the ampersand follows the parameter combo like key[=value]& – nmtoken Jul 16 '18 at 10:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.