OWSLib
OWSLib copied to clipboard
WFS GetFeature Request via GET method does not work in 0.23 and newer
Hi @ferreteleco, I was wondering if you can help me.
I was using owslib version 0.22 without any problem when calling WFS, but in versions 0.23 and newer I got an exception from service. I have investigated that the reason is change in the code commited by you in commit 5392a92b in utils.py.
Code in 0.23 on line 200 is: rkwargs['params'] = unquote(data) if data else None
Code in 0.22 was: rkwargs['params'] = data
I am not sure what was the reason for such unquoting of the data, but in my case it creates badly formatted request.
My request in JSON is:
{'srsname': 'http://www.opengis.net/gml/srs/epsg.xml#3035', 'typename': 'lucas:lucas_points', 'filter': '<ogc:BBOX xmlns:ogc="http://www.opengis.net/ogc"><ogc:PropertyName>geom</ogc:PropertyName><gml311:Envelope xmlns:gml311="http://www.opengis.net/gml" srsName="http://www.opengis.net/gml/srs/epsg.xml#3035"><gml311:lowerCorner>4504276 3020369</gml311:lowerCorner><gml311:upperCorner>4689608 3105290</gml311:upperCorner></gml311:Envelope></ogc:BBOX>'}
The request before unquote looks good:
service=WFS&version=1.1.0&request=GetFeature&srsname=http%3A%2F%2Fwww.opengis.net%2Fgml%2Fsrs%2Fepsg.xml%233035&filter=%3Cogc%3ABBOX+xmlns%3Aogc%3D%22http%3A%2F%2Fwww.opengis.net%2Fogc%22%3E%3Cogc%3APropertyName%3Egeom%3C%2Fogc%3APropertyName%3E%3Cgml311%3AEnvelope+xmlns%3Agml311%3D%22http%3A%2F%2Fwww.opengis.net%2Fgml%22+srsName%3D%22http%3A%2F%2Fwww.opengis.net%2Fgml%2Fsrs%2Fepsg.xml%233035%22%3E%3Cgml311%3AlowerCorner%3E4504276+3020369%3C%2Fgml311%3AlowerCorner%3E%3Cgml311%3AupperCorner%3E4689608+3105290%3C%2Fgml311%3AupperCorner%3E%3C%2Fgml311%3AEnvelope%3E%3C%2Fogc%3ABBOX%3E&typename=lucas%3Alucas_points&propertyname=%2A
But after unquoting looks strage (some characters such as spaces are escaped with + character, but others are not escaped, so it is some kind of mixed escape not escape that the WFS can not parse):
service=WFS&version=1.1.0&request=GetFeature&srsname=http://www.opengis.net/gml/srs/epsg.xml#3035&filter=<ogc:BBOX+xmlns:ogc="http://www.opengis.net/ogc"><ogc:PropertyName>geom</ogc:PropertyName><gml311:Envelope+xmlns:gml311="http://www.opengis.net/gml"+srsName="http://www.opengis.net/gml/srs/epsg.xml#3035"><gml311:lowerCorner>4504276+3020369</gml311:lowerCorner><gml311:upperCorner>4689608+3105290</gml311:upperCorner></gml311:Envelope></ogc:BBOX>&typename=lucas:lucas_points&propertyname=*
Any help appreciated.
Kind regards
Jan
Hi Jan,first of all I'm sorry you had this messed up, and I'll try to help you fix this.
I haven't a pc at hand rn but first I can tell is this is something weird and could be related to "unquote" function from urllib. I had to use it since data gave me some problems(exceptions) when adding headers to a openURL request. The change I made performed well with all WCS request I checked.
Since unquote replaces %xx escapes by their single-character equivalent, there should be no problem. The "+" signs you mention are present in both quoted and unquoted query examples (I think).
Maybe the problem is something regarding how that rkwargs['params'] are used to query a specific server (WFS in your case breaks, my tests in WCS were all fine). Try looking over this and try to figure something more on how that data is used.
I'll try to check it myself asap and give some more information / resolution over the issue you're facing
One more insight on this: as I see in files for WCS and WFS services (both in its V2.0.0) there is a difference in how data parameter for openURL calls are constructed.
For WCS, the data variable is constructed by combining urlencode+param_list_to_url_string function calls.
However, for WFS the functions in charge of generating / formatting data are getPOSTGetFeatureRequest / getGETGetFeatureRequest.
Here may be the point that leads to failure, since inputs for openURL are generated in a different way for both services.
Cheers
Thank you very much. I am surprised that no one reported such problem. Maybe I do something wrong and it is necessary to use getfeature in this version in a different way. Maybe someone can help with functional example.
Please @ferreteleco can you provide functional example for WFS service? Due to https://github.com/geopython/OWSLib/commit/5392a92b9f5b4549d04a5f79ccb9e4bf02990623 is owslib >= 0.23 failing on all WFS request we have tested! Thanks a lot!
I have tried to reproduce this on version 2.0 of WFS and I did not get such error, so probably only version 1.0.0 has such problem.
This works on 0.22 and 0.25. The filter does not work, but it may be problem on provider (CUZK) side.
import owslib
from owslib.wfs import WebFeatureService
print(owslib.__version__)
cuzk = WebFeatureService('http://geoportal.cuzk.cz/wfs_au/wfservice.aspx', version="2.0.0")
args = {'typename': 'gmgml:KRAJ', 'filter': '<ogc:BBOX xmlns:ogc="http://www.opengis.net/ogc"><ogc:PropertyName>geom</ogc:PropertyName><gml311:Envelope xmlns:gml311="http://www.opengis.net/gml" srsName="http://www.opengis.net/gml/srs/epsg.xml#5514"><gml311:lowerCorner>-516343.7 -1134212.5</gml311:lowerCorner><gml311:upperCorner>-509163.2 -1129893.5</gml311:upperCorner></gml311:Envelope></ogc:BBOX>'}
response = cuzk.getfeature(**args)
gml = response.read()
with open('/tmp/x.gml', 'wb') as f:
f.write(gml)