geopython / OWSLib

OWSLib is a Python package for client programming with Open Geospatial Consortium (OGC) web service (hence OWS) interface standards, and their related content models.
https://owslib.readthedocs.io
BSD 3-Clause "New" or "Revised" License
381 stars 273 forks source link

Error on WFS request in 0.9.0 #277

Open paknorton opened 9 years ago

paknorton commented 9 years ago

I've been working through a problem in pyGDP where scripts that used to work mysteriously started crashing. After digging further into the problem I narrowed it down to a problem with the current owslib library (0.9.0). I am using an Anaconda python-2.7 environment with the following library versions. lxml 3.4.4 libxml2 2.9.2 libxslt 1.1.28 owslib 0.9.0 pyGDP 1.3.3

The sample code below always results in the following error in from the xml parser: TypeError: read() takes exactly 1 argument (2 given)

from owslib.wps import WFSQuery
from owslib.wfs import WebFeatureService
from owslib.etree import etree

WFS_URL = 'http://cida.usgs.gov/gdp/geoserver/wfs'
shapefile = 'sample:CONUS_states'

wfs = WebFeatureService(WFS_URL, version='1.1.0')
feature = wfs.getfeature(typename=shapefile, maxfeatures=1, propertyname=None)

gml = etree.parse(feature)

I should note that an error in etree.py with the import of the xml parser initially resulted in the lxml parser never being loaded. In etree.py at about line 36 the import looked like this: try: from lxml import etree, ParseError ....

I had to change it to the following to get lxml to load:

try:
    from lxml import etree
    from lxml.etree import ParseError
    ....

<>

Regardless, both xml and lxml parsers returned the same error. I downgraded owslib to 0.8.13 and the problem went away. I haven't had a chance to do a diff between to the two versions so I'm not sure what the exact problem is but I thought I would bring it to your attention. Let me know if you need further information.

tomkralidis commented 9 years ago

@paknorton when I try:

gml = etree.fromstring(feature)

this works as expected. etree.parse expects a filepath.

paknorton commented 9 years ago

So with 0.9.0 you should use etree.fromstring() for file handles and etree.parse() for filepaths?

tomkralidis commented 9 years ago

@paknorton I think it's always been like this. See:

Now, it looks like OWSLib 0.8.13 was returning a StringIO (file-like) object, where as now it returns owslib.util.ResponseWrapper. I think this is rooted in https://github.com/geopython/OWSLib/commit/1ce3402f2520442126d540e640f2a23d9df70b14

@daf any idea/comments?