for the past couple of days I have been trying to consume a WFS through Python.

I was using owslib but I noticed that the client only uses version 1.0.0 and i tried to apply cql_filters by doing like this

from owslib.wfs import WebFeatureService
from osgeo import gdal
import arcpy
from owslib.fes import *
from xml.etree import ElementTree as ET

filter = PropertyIsLike(propertyname='cql_filter', literal='sorgun', wildCard='*')
filterxml = etree.tostring(filter.toXML()).decode("utf-8")

wfs_link= 'somelink here'

wfs = WebFeatureService(url=wfs_link, version='1.0.0', username = "userX", password = "pw2")

request_data = {"typename":["X:Y"],
                "srsname": "EPSG:4326"}

data = wfs.getfeature(filter= filterxml, **request_data)

So I realized that ows only starts to support to filters with the version of '1.1.0', I cannot apply any filters which does not help me. I tried to give it as a request_data parameter but it gives me error.

Is there any other way to do so or any other library that I can use to consume WFS?


So I discarded the first part of the URL, but the request should look something like this:


1 Answer 1


CQL is not part of the WFS standard, being rather an enhancement that GeoServer offers so you'll need to use an XML filter (as you seem to be trying to do).

The problem is that you aren't creating a valid filter (try printing out filterxml to see what I mean). I'm assuming that you don't actually have an attribute called cql_filter. If you want to fetch all records where an attribute (for example called type) contains the word sorgun you need to do something like:

filter = PropertyIsLike(propertyname='type', literal='*sorgun*', wildCard='*')
filterxml = etree.tostring(filter.toXML()).decode("utf-8")

which will generate a filter xml:

<ogc:PropertyIsLike xmlns:ogc="http://www.opengis.net/ogc" wildCard="*" singleChar="_" escapeChar="\"><ogc:PropertyName>type</ogc:PropertyName><ogc:Literal>*sorgun*</ogc:Literal></ogc:PropertyIsLike>

which is probably going to work.

  • It did not work, i got an 500 Server Error: Intenral Server error for url. However if i put propertyname as "cql_filter" it does not return error but and it is the only keyword that does not return error back. In the documentation they said you should use it like this CQL_FILTER (tapumahallead ilike 'sorgun') @ian-turton
    – Fatih Enes
    Aug 11, 2022 at 7:54
  • Please edit your question with the request that is being generated
    – Ian Turton
    Aug 11, 2022 at 8:24
  • I added the request url to the question.
    – Fatih Enes
    Aug 11, 2022 at 8:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.