OWSLib icon indicating copy to clipboard operation
OWSLib copied to clipboard

getFeature throws exceptions when receiving ServiceException

Open velle opened this issue 2 years ago • 0 comments

Im using OWSlib to query features from a WFS service. The service responds with a ServiceException because the filter is not valid. But OWSlib gives the following error:

Traceback (most recent call last):
  File "5_mapshot.py", line 20, in <module>
    get_wfs = wfs.getfeature(typename=['service2:customers'], filter= filter_xml_str)
  File "/usr/lib/python3/dist-packages/owslib/feature/wfs110.py", line 352, in getfeature
    se = tree.find(nspath_eval("ServiceException", namespaces["ogc"]))
  File "/usr/lib/python3/dist-packages/owslib/util.py", line 269, in nspath_eval
    namespace, element = chunks.split(':')
ValueError: not enough values to unpack (expected 2, got 1)

I suspect that line 352 in wfs110.py is incorrect and should be corrected as shown here:

try:
    tree = etree.fromstring(data)
except BaseException:
    # Not XML
    return makeStringIO(data)
else:
    if tree.tag == "{%s}ServiceExceptionReport" % namespaces["ogc"]:
        #se = tree.find(nspath_eval("ServiceException", namespaces["ogc"])) # throws exception
        se = tree.find(nspath_eval("ogc:ServiceException", namespaces)) # library seems to work
        raise ServiceException(str(se.text).strip())
    else:
        return makeStringIO(data)

The above correction makes OWSlib throw a "owslib.util.ServiceException: Filter is not valid" instead, which I believe is the correct behavior.

Im using OSWlib 0.19.1.

Because I am far from fluent in git I am not able to correct the code myself. Let me know if you need more details. Sincerely :)

velle avatar Sep 05 '22 11:09 velle